zoukankan      html  css  js  c++  java
  • 点击加载更多

    <!DOCTYPE html>
    <html>
    <head>
    <title>无限翻页测试</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <style type="text/css">
    #spinner{
    position: fixed;
    bottom: 20px;
    left: 40%;
    display: block;
    color: red;
    font-weight: 900;
    background-color: rgba(80, 80, 90, 0.22);
    padding-top: 20px;
    padding-bottom: 20px;
    padding-left: 100px;
    padding-right: 100px;
    border-radius: 15px;
    }
    </style>
    </head>
    <body>
    <div id="sample">
    </div>
    <div id="spinner" onclick="checkScroll()">
    正在加载
    </div>
    <script type="text/javascript">
    var index = 0;
    function lowEnough(){
    var pageHeight = Math.max(document.body.scrollHeight,document.body.offsetHeight);
    var viewportHeight = window.innerHeight ||
    document.documentElement.clientHeight ||
    document.body.clientHeight || 0;
    var scrollHeight = window.pageYOffset ||
    document.documentElement.scrollTop ||
    document.body.scrollTop || 0;
    // console.log(pageHeight);
    // console.log(viewportHeight);
    // console.log(scrollHeight);
    return pageHeight - viewportHeight - scrollHeight < 20;
    }

    function doSomething(){
    var htmlStr = "";
    for(var i=0;i<10;i++){
    htmlStr += "这是第"+index+"次加载<br>";
    }
    $('#sample').append(htmlStr);
    index++;
    return;
    pollScroll();//继续循环

    $('#spinner').hide();

    }

    function checkScroll(){
    if(!lowEnough()) return pollScroll();

    $('#spinner').show();

    setTimeout(doSomething,900);

    }
    function pollScroll(){
    setTimeout(checkScroll,1000);
    }

    </script>
    </body>
    </html>
  • 相关阅读:
    .net程序运行
    vc mscom控件串口接收不到数据问题
    vc 显示非模态对话框
    vc 使用SetWindowPos改变窗体的大小,实现折叠,展开
    c# 串口问题
    vc 电脑发声程序
    Java问题定位技术
    Java性能调优笔记
    shell解析xml文档
    Unix/Linux 的 Load 初级解释
  • 原文地址:https://www.cnblogs.com/zcboy/p/7109543.html
Copyright © 2011-2022 走看看