Great example but I had to customize it in order to scroll up/down if top/bottom portion of element was not in viewport. I also stripped out horizontal checks as I only need to scroll vertically to selected element.
$.fn.isOnScreen = function(el){
var win = $(window);
var bounds = el.offset();
Great example but I had to customize it in order to scroll up/down if top/bottom portion of element was not in viewport. I also stripped out horizontal checks as I only need to scroll vertically to selected element.
$.fn.isOnScreen = function(el){
var win = $(window);
var bounds = el.offset();
var viewport = {
top : win.scrollTop()
};
viewport.bottom = viewport.top + win.height();
bounds.bottom = bounds.top + el.outerHeight();
return (!(viewport.bottom < bounds.top || viewport.bottom < bounds.bottom || viewport.top > bounds.bottom || viewport.top > bounds.top));
};