Home > Web Front-end > JS Tutorial > How to achieve infinite page loading using js and jquery

How to achieve infinite page loading using js and jquery

一个新手
Release: 2017-09-18 10:14:28
Original
2331 people have browsed it

Example:
Jingdong mobile version page product list
How to achieve infinite page loading using js and jquery
First define the page scroll event scroll binding function

$(window).on("scroll", function() {
    scrollFunction();
})
Copy after login

Then define the function scrollFunction()

function scrollFunction() {
    var e = $("#page-num");
    e.scrollTop  = $(window).scrollTop();
    e.scrollStar = e.scrollEnd;
    e.scrollEnd  = $(window).scrollTop();    // 分页显示
    if (e.scrollStar != e.scrollEnd) {        // 当滚动的时候 显示分页信息 显示1秒
        setTimeout(function() {
            e.hide();
        }, 1000);        
        var j = null;        
        var l = $(window).height();        
        var d = $(window).scrollTop();        // 新页的产品列表 页数写在 li 标签里 然后循环所有的这个标签 
        p_lis = $("#goods-ul").find("li");
        p_lis_size = p_lis.size();        
        for(var ss= 0; ss < p_lis_size; ss++){
            f = $(p_lis[ss]);            
            var k = f.offset().top; // 这个元素(相对于文档)的 偏移距离
            // 偏移距离 大于windows 滚动距离 且 小于滚动距离+页面高度 的用来当作当前页数
            if (k >= d && k < (d + l)) {
                j = f.attr("data-page");
            }
        }        if(j){
            $("#currentPage").text(j);
        }

        e.show();
    }

}
Copy after login

Sample of each element on the page:
How to achieve infinite page loading using js and jquery

The above is the detailed content of How to achieve infinite page loading using js and jquery. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template