zoukankan      html  css  js  c++  java
  • jq分页滚动加载数据

    //html
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title></title>
        <link rel="stylesheet" href="./css/days.css">
        <script src="js/jquery-3.1.1.min.js" type="text/javascript" charset="utf-8"></script>
        <script type="text/javascript" src="./js/days.js"></script>
    </head>
    <body>
        <div class="wrap">
            <div class="main"></div>
        </div>
        <script>
        </script>
    </body>
    </html>
    
    
    //js
    $(function() {
        var url = "https://";
        var pageNum = 0; // 当前页码
        var pageSize = 7; // 当前每页条数 
        var openid = ""
        $(function() {
            $(window).scroll(function() {
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();
                if (scrollTop + windowHeight == scrollHeight) {  //此处是滚动条到底部时候触发的事件,在这里写要加载的数据,或者是拉动滚动条的操作
                    pageNum++
                    days()
                }
            });
            days()
        })
        var days = function(data) {
            var html = '';
            $.ajax({
                type: "post",
                contentType: "application/json",
                url: url + "/query",
                data: JSON.stringify({
                    "openId": openid,
                    "pageSize": pageSize,
                    "pageNum": pageNum
                }),
                success: function(res) {
                    var res = JSON.parse(res)
                    console.log(res.datas)
                    if (res.datas.length > 0) {
                        res.datas.map(function(item, index, arr) {
                                html += `
                                <li class="List">
                                    <div class="main">
                                        <div>${item.name}</div>
                                        <div>¥${item.sex}</div>
                                    </div>
                                </li>
                            `;
                        });
                        $(".main").append(html);
                    }
                }
            })
        }
    })
  • 相关阅读:
    JS判断是PC端还是移动端
    js对象转数组
    js获取当前域名、Url、相对路径和参数以及指定参数
    javascript返回上一页的三种写法
    js正则归纳总结
    higtcharts 生成图表个数问题
    js如何处理后台传递过来的Map
    jQuey实现鼠标滑过整行变色
    <display:column>常用属性解释
    <display:table>常用属性解释
  • 原文地址:https://www.cnblogs.com/minghan/p/13864154.html
Copyright © 2011-2022 走看看