requirejs_list.html 2.9 KB
<!-- 
        作者:dailc
        时间:2018-01-24
        描述: requirejs引入示例
-->
<!DOCTYPE html>
<html lang="zh-CN">

    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <title>requirejs引入示例</title>
        <link rel="stylesheet" href="../../dist/debug/minirefresh.css" />
        <link rel="stylesheet" href="../common/common.css" />
    </head>

    <body>

        <nav class="navbar-header">
            <a class="nav-btn-left" href="../index.html">dashboard</a>
            requirejs引入示例
        </nav>
        <div class="content">
            <div id="minirefresh" class="minirefresh-wrap">

                <div class="minirefresh-scroll">

                    <ul class="data-list" id="listdata">

                    </ul>
                </div>
            </div>
        </div>

        <script type="text/javascript" src="require.js" ></script>
        <script>
            // common里是全局变量声明形式
            requirejs(["../../dist/debug/minirefresh.js", '../common/common.js'], function(MiniRefreshTools) {
                //This function is called when scripts/helper/util.js is loaded.
                //If util.js calls define(), then this function is not fired until
                //util's dependencies have loaded, and the util argument will hold
                //the module value for "helper/util".
                console.log(MiniRefreshTools);
                var MiniRefresh = MiniRefreshTools.theme.defaults;
                var appendTestData = Common.appendTestData,
                    // 记录一个最新
                    maxDataSize = 30,
                    listDom = document.querySelector('#listdata'),
                    requestDelayTime = 600;

                var miniRefresh = new MiniRefresh({
                    container: '#minirefresh',
                    down: {
                        callback: function() {
                            setTimeout(function() {
                                // 每次下拉刷新后,上拉的状态会被自动重置
                                appendTestData(listDom, 10, true);
                                miniRefresh.endDownLoading(true);
                            }, requestDelayTime);
                        }
                    },
                    up: {
                        isAuto: true,
                        callback: function() {
                            setTimeout(function() {
                                appendTestData(listDom, 10);
                                miniRefresh.endUpLoading(listDom.children.length >= maxDataSize ? true : false);
                            }, requestDelayTime);
                        }
                    }
                });
            });
        </script>
    </body>

</html>