开发者

Looking for a script similar to jquery.inview that allows div to be loaded as user scrolls

开发者 https://www.devze.com 2023-02-22 09:54 出处:网络
I\'ve been searching tirelessly开发者_Python百科 to find a script that as a user scrolls down a page, content is loaded.

I've been searching tirelessly开发者_Python百科 to find a script that as a user scrolls down a page, content is loaded.

I have a page with multiple images that span down a page and would like to use this script to speed up the initial page load. The content on the page is static, so I would prefer the content to be appended to the page as it is scrolled.

Any help is really appreciated!

Thanks


You don't need a plugin for this. With jQuery you can do

$(window).scroll(function () { 
   if ($(window).scrollTop() >= $(document).height() - $(window).height() - 10) {
      //Add something at the end of the page
   }
});

Check working example at http://jsfiddle.net/6hPHn/2/


Depending what exactly you are trying to load and when, Waypoints might be part of a potential solution.


This library adds an inview event to bind to so it's really easy to read and maintain. https://github.com/protonet/jquery.inview I've also used Waypoints but I feel this is a easier to get started with.

$("#divId").on("inview" fn);

$("#loadMeLater").on("inview",function(){
  // Remove event handler after the element has been viewed
  $(this).off("inview");
  // Change something on screen after a short timer
  setTimeout(inViewHandler,'200');
});
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号