Guest User

Untitled

a guest
Jun 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. $.belowViewport = function(elem){
  2. var port = $(window).scrollTop() + $(window).height();
  3. return port <= $(elem).offset().top;
  4. }
  5.  
  6. $.fn.onBecomeVisible = function( fn ){
  7. var obj = this;
  8. $(window).scroll( function() {
  9. obj.each( function() {
  10. if(!$.belowViewport(this) && !$(this).data('scrollEventFired')){
  11. $(this).data('scrollEventFired', true);
  12. fn(this);
  13. }
  14. });
  15. });
  16. return this;
  17. }
  18.  
  19. $('.elements:last').onBecomeVisible( function(elem){ loadNewElems(); } );
Add Comment
Please, Sign In to add comment