nested_swipe.html 5.58 KB
<!-- 
        作者:dailc
        时间:2017-08-29
        描述: 嵌套swipe
-->
<!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>nested swipe</title>
        <link rel="stylesheet" href="libs/swipe/css/swiper.min.css" />
        <link rel="stylesheet" href="../../dist/debug/minirefresh.css" />
        <link rel="stylesheet" href="../common/common.css" />
        <style>
            .navbar-header {
                border-bottom: none;
            }
            
            .swiper-container {
                position: absolute;
                top: 90px;
                left: 0;
                width: 100%;
                height: 100%;
            }
            
            .minirefresh-wrap {
                top: 0;
            }
        </style>
    </head>

    <body>

        <nav class="navbar-header">
            <a class="nav-btn-left" href="../index.html">dashboard</a>
            嵌套swipe
        </nav>
        <div class="content">
            <div class="nav-control">
                <p class="active" list-type="0">列表0</p>
                <p list-type="1">列表1</p>
                <p list-type="2">列表2</p>
            </div>
            <div class="swiper-container">
                <div class="swiper-wrapper">
                    <div class="swiper-slide">
                        <div id="minirefresh0" class="minirefresh-wrap">
                            <div class="minirefresh-scroll">
                                <ul class="data-list" id="listdata0">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="swiper-slide">
                        <div id="minirefresh1" class="minirefresh-wrap">
                            <div class="minirefresh-scroll">
                                <ul class="data-list" id="listdata1">
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="swiper-slide">
                        <div id="minirefresh2" class="minirefresh-wrap">
                            <div class="minirefresh-scroll">
                                <ul class="data-list" id="listdata2">
                                </ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>

        <script type="text/javascript" src="libs/swipe/js/swiper.min.js"></script>
        <script type="text/javascript" src="../../dist/debug/minirefresh.js"></script>
        <script type="text/javascript" src="../common/common.js"></script>
        <script>
            var appendTestData = Common.appendTestData,
                bindEvent = Common.bindEvent,
                // 记录一个最新
                maxDataSize = 30,
                listDomArr = [],
                requestDelayTime = 600,
                miniRefreshArr = [],
                currIndex = 0;

            var initMiniRefreshs = function(index) {

                listDomArr[index] = document.querySelector('#listdata' + index);

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

            var navControl = document.querySelector('.nav-control');

            var mySwiper = new Swiper('.swiper-container', {
                autoplay: 0,
                onSlideChangeEnd: function(swiper) {
                    var index = swiper.activeIndex;

                    console.log('滑动');
                    navControl.querySelector('.active').classList.remove('active');
                    navControl.children[index].classList.add('active');
                    currIndex = index;
                }
            });

            bindEvent('.nav-control p', function(e) {
                var type = this.getAttribute('list-type');

                type = +type;
                
                console.log(type +',' + currIndex);

                if (type !== currIndex) {
                    navControl.querySelector('.active').classList.remove('active');
                    this.classList.add('active');


                    currIndex = type;

                    mySwiper.slideTo(currIndex, 500);
                }
            }, 'click');

            initMiniRefreshs(0);
            initMiniRefreshs(1);
            initMiniRefreshs(2);
        </script>
    </body>

</html>