Ajax - limit the loading of a list and then load the rest on scroll

痞子三分冷 提交于 2019-12-03 21:23:13

This is a concept called infinite scrolling. Google for that, and you'll find what you're looking for.

infinite-scroll-jquery-plugin is a jQuery plugin that will support what you're trying to do, and there are others.

Although it doesn't fix the loading time issue, I created a fairly simple jquery solution to the infinite scrolling without the need for a plugin.

$("#CategoryContent li").slice(20).hide();

Which hides all but the first 20 products in the list.

var mincount = 20;
var maxcount = 40;


$(window).scroll(function() 
                    {
                    if($(window).scrollTop() + $(window).height() >= $(document).height() - 400) {
                            $("#CategoryContent li").slice(mincount,maxcount).fadeIn(800);

mincount = mincount+20;
maxcount = maxcount+20

}
});

Waits for the user to scroll past 400px from the bottom of the page, then fades in the next 20, and repeats until all of the products are loaded.

Unless you find a plugin like the one in your link, You would need to return your Ajax in JSON most likely, then go through then process the values from there into your page.

I would suggest you read the documentation on the $.get() or the $.getJSON() for more assistance with this. You should find examples here on how to parse through the JSON data as well on these links.

It should improve load time if you're loading only 20 records at a time instead of 100's at once.

Ajax and SEO, there are certain techniques people use to accomplish this, but I'm not sure if it is as positive for SEO as normal non-ajax content to the web spider. Here is a resource I was able to find online about this subject: http://www.searchenginejournal.com/seo-for-ajax/19138/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!