// function to detect passed element is appear or not
$.fn.isOnScreen = function(){var win = $(window);
var viewport = {
top : win.scrollTop(),
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = this.offset();
bounds.right = bounds.left + this.outerWidth();
bounds.bottom = bounds.top + this.outerHeight();
return (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom));
};
// Just replace this line with your id, tag, class
var isthere = $('#yourid').isOnScreen();if(isthere == true)
{
// Do something for appear
}
else
{
// Do something not appear
}
No comments:
Post a Comment