Looking for a script similar to jquery.inview that allows div to be loaded as user scrolls
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');
});
精彩评论