/ Published in: JavaScript

Copied from somewhere, probably stackoverflow.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var checkViewport = function(el){ var minTop = jQuery(document).scrollTop(), minLeft = jQuery(document).scrollLeft(), maxTop = minTop + jQuery(window).height(), maxLeft = minLeft + jQuery(window).width(), $myElement = el, elementOffset = $myElement.offset(), elementHeight = $myElement.height(), elementWidth = $myElement.width(); if ( (elementOffset.top > minTop && elementOffset.top + elementHeight < maxTop) && (elementOffset.left > minLeft && elementOffset.left + elementWidth < maxLeft) ) { console.log('entire element is visible'); } else { console.log('entire element is not visible'); } }
Comments
