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

    话不多说,直接上代码,有些地方需要加自己的逻辑,自己加

    <!DOCTYPE html>
    <html>
    <head lang="en">
    <meta charset="UTF-8">
    <title>滚动条测试</title>

    <style>
    .parent_div {
    auto;
    height: auto
    }
    .lostfound-text{
    200px;
    height: 50px;
    border: 1px red solid;
    }
    </style>
    </head>
    <body>

    <div class="parent_div">
    <div style=" 100%;height: 500px;border: black 1px solid;"></div>
    <ul id="my_list">
    <li class="lostfound-text">This is list item origin.</li>
    </ul>
    </div>


    <script src="js/jquery.min.js"></script>
    <script>
    $(function(){

    var pos = 0;
    var LIST_ITEM_SIZE = 2;
    //滚动条距底部的距离
    var BOTTOM_OFFSET = 0;
    createListItems();
    $(document).ready(function () {
    $(window).scroll(function () {
    var $currentWindow = $(window);
    //当前窗口的高度
    var windowHeight = $currentWindow.height();
    //当前滚动条从上往下滚动的距离
    var scrollTop = $currentWindow.scrollTop();
    //当前文档的高度
    var docHeight = $(document).height();
    //当 滚动条距底部的距离 + 滚动条滚动的距离 >= 文档的高度 - 窗口的高度
    //换句话说:(滚动条滚动的距离 + 窗口的高度 = 文档的高度) 这个是基本的公式
    if ((BOTTOM_OFFSET + scrollTop) >= docHeight - windowHeight) {

    //这里可以写判断逻辑
    createListItems();
    }
    });
    });
    function createListItems() {
    var mylist = $("#my_list");
    for (var i = pos; i < pos + LIST_ITEM_SIZE; ++i) {
    let x='<li class="lostfound-text">This is list item origin.</li>';
    mylist.append(x);
    }
    pos += LIST_ITEM_SIZE;
    }

    })

    </script>
    </body>
    </html>

  • 相关阅读:
    【CodeForces 788B】奇妙的一笔画问题
    数论day2——离散对数、元根
    学习阶段总结(1)
    Flask特殊装饰器
    Flask蓝图
    Flask对象配置
    Flask实例化配置
    Flask路由
    Flask Session
    Flask jinja2
  • 原文地址:https://www.cnblogs.com/changefl/p/10845630.html
Copyright © 2011-2022 走看看