Infinite Scrolling without ajax using jquery? [closed]

社会主义新天地 提交于 2019-12-11 14:28:28

问题


I want to create infinite scroll in jquery mobile web application.I want to scroll the page without using ajax.Is there any possibility to do that?


回答1:


If your data isn't really infinite, you may store everything in the page and show the ones that needs to be shown.

For example (not tested, but to give you an idea):

HTML

<div class="scrollable-data"><!-- ... --></div>
<div class="scrollable-data"><!-- ... --></div>
<div class="scrollable-data"><!-- ... --></div>
<div class="scrollable-data"><!-- ... --></div>

jQuery

var $doc=$(document);
var $win=$(window);

// hide everything that is out of bound
$('.scrollable-data').filter(function(index){
    return ($(this).scrollTop() > $doc.height());
}).hide();

var DATA_INCREMENT=5;

$(window).scroll(function(){
    // test if at the bottom
    if ($doc.height()-$win.height()-$(this).scrollTop() == 0) {
        // show the <DATA_INCREMENT> (5) next hidden data tags
        $('.scrollable-data:hidden:lt('+DATA_INCREMENT+')').show();
    }
});

Hope this helps.



来源:https://stackoverflow.com/questions/20042121/infinite-scrolling-without-ajax-using-jquery

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