<!doctype html>
<html>
    <head>
        <title>jquery 手机端上拉刷新下拉加载更多页面</title>
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
        <meta name="viewpost" content="width=device-width, initial-scale=1.0, user-scalable=0,minimum-scale=1.0, maximum-scale=1.0">
        <meta name="apple-moblie-web-app-capable" content="yes">
        <meta name="apple-moblie-web-app-status-bar-style" content="black">
        <link rel="stylesheet" href="reset.css" />
        <link rel="stylesheet" href="pullToRefresh.css" />
        <script src="iscroll.js"></script>
        <script src="pullToRefresh.js"></script>
    </head>
    <style>
        body, html {
            padding: 0;
            margin: 0;
            height: 100%;
            font-family: Arial, Microsoft YaHei;
            color: #111;
        }
        li {
            border: 1px solid #e7e7e7;
            text-align: center;
            line-height: 80px;
        }
    </style>
    
    <body>
        <div id="wrapper">
            <ul>
                <li>row 10</li>
                <li>row 9</li>
                <li>row 8</li>
        <!--         <li>row 7</li>
                <li>row 6</li>
                <li>row 5</li>
                <li>row 4</li>
                <li>row 3</li>
                <li>row 2</li>
                <li>row 1</li> -->
            </ul>
        </div>
    </body>
    
</html>

<script>
    refresher.init({
        id: "wrapper",
        pullDownAction: Refresh,
        pullUpAction: Load
    })
    var generatedCount = 0;
        function Refresh() {  //上拉要执行的代码
            setTimeout(function () {    // <-- Simulate network congestion, remove setTimeout from production!
                var el, li, i;
                el = document.querySelector("#wrapper ul");
                el.innerHTML = '';
                for (i = 0; i < 2; i++) {
                    li = document.createElement('li');
                    li.appendChild(document.createTextNode('async row ' + (++generatedCount)));
                    el.insertBefore(li, el.childNodes[0]);
                }
                wrapper.refresh();/****remember to refresh after  action completed! ---yourId.refresh(); ----| ****/
           
            }, 1000);

        }

        function Load() {  //下拉要加载的代码  
            setTimeout(function () {// <-- Simulate network congestion, remove setTimeout from production!
                var el, li, i;
                el = document.querySelector("#wrapper ul");
                for (i = 0; i < 2; i++) {
                    li = document.createElement('li');
                    li.appendChild(document.createTextNode('async row ' + (++generatedCount)));
                    el.appendChild(li, el.childNodes[0]);
                }
                wrapper.refresh();/****remember to refresh after action completed!!!   ---id.refresh(); --- ****/
              
            }, 1000);
        }
</script>
index.html

相关文章: