javascript - How to get amount of portions of a HTML element is visible in viewport -
- is possible know whether or not html element image viewable in current viewport or visible on scroll?
- if viewable or partially how can amount of portions visible?
i trying explain following image: 
the 2 images @ bottom partially visible within viewport , these visible if 1 scroll down little bit.
now want the aforesaid information.
in actual scenario trying popup-zoom effect on hover of image in album google image search. fine, except if images placed in described manner zoomed div displaying in half.
normal condition image in viewport: 
and partially in viewport: 
i appreciate help.
the code:
var albumdetailonready = function() { $('.image').each(function(){ var photo = $(this); var wrap = $(findparentbyclassname(document.getelementbyid(photo.attr('id')), 'wrap')); var row = $(findparentbyclassname(document.getelementbyid(wrap.attr('id')), 'albumdetailrow')); var visiblezone = $(wrap).find('.aldtlcolumn'); var pictureblock = $(visiblezone).find('.pictuteblock'); var hiddenzone = $(wrap).find('.hiddenzone'); $(photo).load(function(){ if(177 > $(photo).width()){ var imgleft = ($(pictureblock).width() - $(photo).width())/2 + 'px'; $(photo).css({'left': imgleft}); } }); $(photo).hover(function(){ var y; if($(photo).height() > $(photo).width()) { y = ($(visiblezone).offset().top - 50) + 'px'; } else { y = ($(visiblezone).offset().top + 50) + 'px'; } var x; if($(row).find('.wrap:first').attr('id') === $(wrap).attr('id')) { x = ($(visiblezone).offset().left - 10) + 'px'; } else if($(row).find('.wrap:last').attr('id') === $(wrap).attr('id')) { x = ($(visiblezone).offset().left - 50) + 'px'; } else { x = ($(visiblezone).offset().left - 20) + 'px'; } $(hiddenzone).css({ 'top': y, 'left': x, 'position': 'absolute', 'z-index': '10' }); $(hiddenzone).fadein('fast'); }, function(){ }); $(hiddenzone).hover(function(){},function(){ $(hiddenzone).hide().stop(true, true); }); }); } var findparentbyclassname = function(element, clazz) { while (element.parentnode) { element = element.parentnode; if (hasclass(element, clazz)) { return element; } } return null; } function hasclass(element, cls) { var regex = new regexp('\\b' + cls + '\\b'); return regex.test(element.classname); } i unable show html haven't have any, working in adf framework.
but explanation:
i have 2 zone each image: visible , hidden. both of them in wrap. on hover image showing hidden div. top , left of hidden div measured top , left of visible div condition.
jquery.viewport
very helpfull , lightweight jquery plugin makes element handy viewport displaying elements absolute position. plugin hosted on github. can see in action right there:
Comments
Post a Comment