Share the post "Detect If Element Is On Screen Or Not Using JQuery"
Out of all the posts that I came across with, this one worked.
|
1 2 3 4 5 6 7 8 9 |
$.fn.isOnScreen = function(){ var viewport = {}; viewport.top = $(window).scrollTop(); viewport.bottom = viewport.top + $(window).height(); var bounds = {}; bounds.top = this.offset().top; bounds.bottom = bounds.top + this.outerHeight(); return ((bounds.top <= viewport.bottom) && (bounds.bottom >= viewport.top)); }; |
To use it, do it like this:
|
1 |
$('MyElement').isOnScreen(); |
This code came from upshots.org.