Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $.belowViewport = function(elem){
- var port = $(window).scrollTop() + $(window).height();
- return port <= $(elem).offset().top;
- }
- $.fn.onBecomeVisible = function( fn ){
- var obj = this;
- $(window).scroll( function() {
- obj.each( function() {
- if(!$.belowViewport(this) && !$(this).data('scrollEventFired')){
- $(this).data('scrollEventFired', true);
- fn(this);
- }
- });
- });
- return this;
- }
- $('.elements:last').onBecomeVisible( function(elem){ loadNewElems(); } );
Add Comment
Please, Sign In to add comment