JavaScript
4
Вклад в тег
$.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));
};
var isVisible = function(){
return $('#selector').isOnScreen() // true or false
};
window.addEventListener('scroll', _.debounce(isVisible, 300), false);