Heim  >  Artikel  >  Web-Frontend  >  基于JQuery实现滚动到页面底端时自动加载更多信息_jquery

基于JQuery实现滚动到页面底端时自动加载更多信息_jquery

WBOY
WBOYOriginal
2016-05-16 17:01:52929Durchsuche

关键代码:

复制代码 代码如下:

var stop=true;
$(window).scroll(function(){
    totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
    if($(document).height()         if(stop==true){
            stop=false;
            $.post("ajax.php", {start:1, n:50},function(txt){
                $("#Loading").before(txt);
                stop=true;
            },"text");
        }
    }
});

HTML:

复制代码 代码如下:

Loading...

实现方法是比较页面总高度和下滚高度以判断是否到达底端,若到达底端则通过ajax读取更多的内容,用before插入到Loading之前。
stop参数是考虑到ajax读取耗时,防止在一次ajax读取过程中多次触发事件,造成多次加载内容。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn