mui 单页面下拉刷新

<!DOCTYPE html>
<html>

    <head>
        <meta charset="utf-8">
        <title>Hello MUI</title>
        <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">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">

        <link rel="stylesheet" href="../css/mui.min.css">
        <style>
            html,
            body {
                background-color: #efeff4;
            }
            .mui-pull-top-tips {
                position: absolute;
                top: -20px;
                left: 50%;
                margin-left: -25px;
                width: 40px;
                height: 40px;
                border-radius: 100%;
                z-index: 1;
            }
            .mui-pull-top-wrapper {
                width: 42px;
                height: 42px;
                display: block;
                text-align: center;
                background-color: #efeff4;
                border: 1px solid #ddd;
                border-radius: 25px;
                background-clip: padding-box;
                box-shadow: 0 4px 10px #bbb;
                overflow: hidden;
            }
            .mui-pull-top-tips.mui-transitioning {
                -webkit-transition-duration: 200ms;
                transition-duration: 200ms;
            }
            .mui-pull-top-canvas canvas {
                width: 40px;
            }
            .mui-slider-indicator.mui-segmented-control {
                background-color: #efeff4;
            }

        </style>
    </head>

    <body>
        <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">mui下拉刷新</h1>
        </header>

            <div id="slider" class="mui-slider mui-fullscreen">
                <div class="mui-slider-group">
                    <div id="item1mobile" class="mui-slider-item mui-control-content mui-active">
                        <div class="mui-scroll-wrapper">
                            <div class="mui-scroll">
                                <ul class="mui-table-view">
                                    <li class="mui-table-view-cell">
                                        选项卡子项-1
                                    </li>
                                    <li class="mui-table-view-cell">
                                        选项卡子项-2
                                    </li>
                                    <li class="mui-table-view-cell">
                                        选项卡子项-3
                                    </li>
                                    <li class="mui-table-view-cell">
                                        选项卡子项-4
                                    </li>
                                    <li class="mui-table-view-cell">
                                        选项卡子项-5
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        <script src="../js/mui.min.js"></script>
        <script src="../js/mui.pullToRefresh.js"></script>
        <script src="../js/mui.pullToRefresh.material.js"></script>
        <script>
            mui.init();
            (function($) {
                //阻尼系数
                var deceleration = mui.os.ios?0.003:0.0009;
                $(‘.mui-scroll-wrapper‘).scroll({
                    bounce: false,
                    indicators: true, //是否显示滚动条
                    deceleration:deceleration
                });
                $.ready(function() {
                    //循环初始化所有下拉刷新,上拉加载。
                    $.each(document.querySelectorAll(‘.mui-slider-group .mui-scroll‘), function(index, pullRefreshEl) {
                        $(pullRefreshEl).pullToRefresh({
                            down: {
                                callback: function() {
                                    var self = this;
                                    setTimeout(function() {
                                        var ul = self.element.querySelector(‘.mui-table-view‘);
                                        ul.insertBefore(createFragment(ul, index, 10, true), ul.firstChild);
                                        self.endPullDownToRefresh();
                                    }, 1000);
                                }
                            },
                        });
                    });
                    var createFragment = function(ul, index, count, reverse) {
                        var length = ul.querySelectorAll(‘li‘).length;
                        var fragment = document.createDocumentFragment();
                        var li;
                        for (var i = 0; i < count; i++) {
                            li = document.createElement(‘li‘);
                            li.className = ‘mui-table-view-cell‘;
                            li.innerHTML = ‘选项卡子项-‘ + (length + (reverse ? (count - i) : (i + 1)));
                            fragment.appendChild(li);
                        }
                        return fragment;
                    };
                });
            })(mui);

        </script>
    </body>

</html>
<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
        <title></title>
        <link rel="stylesheet" href="../css/mui.min.css" />
    </head>

    <body>

        <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">公告1</h1>
        </header>
        <div class="mui-content">

         <div id="slider" class="mui-slider mui-fullscreen">
                <div class="mui-slider-group" id="pullrefresh">
                    <div id="item1mobile" class="mui-slider-item mui-control-content mui-active">
                        <div class="mui-scroll-wrapper">
                            <div class="mui-scroll">
                                <ul id="list" class="mui-table-view">

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

                </div>
            </div>
        </div>
        <script src="../js/mui.min.js"></script>
        <script src="../js/mui.pullToRefresh.js"></script>
        <script src="../js/mui.pullToRefresh.material.js"></script>
        <script src="../js/api.js"></script>
        <script>
            mui.init();
            var count = 1;
            (function($) {
                //阻尼系数
                var deceleration = mui.os.ios?0.003:0.0009;
                $(‘.mui-scroll-wrapper‘).scroll({
                    bounce: false,
                    indicators: true, //是否显示滚动条
                    deceleration:deceleration
                });

                $.ready(function() {
                    //循环初始化所有下拉刷新,上拉加载。

                    $.each(document.querySelectorAll(‘.mui-slider-group .mui-scroll‘), function(index, pullRefreshEl) {
                        $(pullRefreshEl).pullToRefresh({
                            down: {
                                callback: function() {
                                    var self = this;
                                    setTimeout(function() {
                                        count=1;
                                        ajax_get_data(this,‘down‘,1);
                                        self.endPullDownToRefresh();
                                    }, 1000);
                                }
                            },
                            up: {
                                contentrefresh: ‘正在加载...‘,
                                callback: function() {
                                    var self = this;
                                    setTimeout(function() {
                                        count=count+1;
                                          ajax_get_data(this,‘up‘,count);
                                        self.endPullUpToRefresh();
                                    }, 1000);
                                }
                            },
                        });
                    });
                    var ajax_get_data = function(self,type,count) {
                        user_token = localStorage.getItem("user_token");
                        user_token_obj = JSON.parse(user_token);
                        mui.ajax(api_url + ‘/public/laoodao_oa/?service=Notice.get_notice_list‘, {
                            data: {
                                token: user_token_obj.token,
                                page: count
                            },
                            dataType: ‘json‘,
                            type: ‘get‘,
                            timeout: 10000,
                            crossDomain: true,
                            async: false,
                            success: function(data) {
                                if(data.data.code > 0) {
                                    var str="";
                                    var fragment = document.createDocumentFragment();
                                    mui.each(data.data.data, function(index, item) {
                                        //字符串拼接
                                        str +="<a href=‘gonggao_xqy.html‘><li class=\"mui-card\">" +
                                                "<div class=\"zbcolor\"></div>" +
                                                "<div class=\"mui-card-content\">" +
                                                "<div class=\"mui-card-content-inner\">" +
                                                "<p class=\"txtTitle\">" + item.pubdate.substring(0, 4) + "年 " + item.title + "</p>" +
                                                "<p class=\"txtContent\">" + item.my_desc + "</p>" +
                                                "<p class=\"txtNote\"><span class=\"mui-pull-left\">" + item.pubdate + " " + item.publisher + "</span><span class=\"mui-pull-right\"></span></p>" +
                                                "</div>" +
                                                "</div>"+
                                                "</a>";
                                                "</li>";

                                        //fragment拼接
                                        li = document.createElement(‘li‘);
                                        li.className = ‘mui-card‘;
                                        li.innerHTML = "<a href=‘gonggao_xqy.html‘><div class=\"zbcolor\"></div>" +
                                                "<div class=\"mui-card-content\">" +
                                                "<div class=\"mui-card-content-inner\">" +
                                                "<p class=\"txtTitle\">" + item.pubdate.substring(0, 4) + "年 " + item.title + "</p>" +
                                                "<p class=\"txtContent\">" + item.my_desc + "</p>" +
                                                "<p class=\"txtNote\"><span class=\"mui-pull-left\">" + item.pubdate + " " + item.publisher + "</span><span class=\"mui-pull-right\"></span></p>" +
                                                "</div>" +
                                                "</div>"+
                                                "</a>";
                                        fragment.appendChild(li);

                                    });
                                    if(type=="down")
                                    {

                                        var ul = document.getElementById("list");
                                        ul.innerHTML=str;
                                    }
                                    if(type=="up")
                                    {
                                        var ul = document.getElementById("list");
                                        ul.appendChild(fragment);
                                    }

                                    console.log(count);
                                }else{
                                    mui.toast(data.data.msg);

                                }

                            }
                        }
                        );
                    };

                    ajax_get_data(null,‘down‘,1);

                    var change_color = function() {
                        for(var i = 0; i < mui(".zbcolor").length; i++) {
                            var mod = (i % 5);
                            switch(mod) {
                                case 0:
                                    mui(".zbcolor")[i].style.background = "#FF8F09";
                                    break;
                                case 1:
                                    mui(".zbcolor")[i].style.background = "#FD686C";
                                    break;
                                case 2:
                                    mui(".zbcolor")[i].style.background = "#F7B449";
                                    break;
                                case 3:
                                    mui(".zbcolor")[i].style.background = "#07C391";
                                    break;
                                case 4:
                                    mui(".zbcolor")[i].style.background = "#A79CCB";
                                    break;
                            }
                        }
                    }

                });

            })(mui);

        </script>
    </body>

</html>
时间: 2024-11-06 12:13:50

mui 单页面下拉刷新的相关文章

使用mui.js实现下拉刷新

闲聊: 最近因公司项目需求,小颖需要写一些html5页面,方便公司IOS和Android给APP中嵌套使用,其中需要实现拉下刷新功能,其实就是调用了一下mui.js就可以啦嘻嘻,下面跟着小颖一起来看看具体是怎么实现的吧. 目录: 效果图: mui.min.js.mui.min.css和jquery-3.3.1.js 小颖就不粘贴啦,大家在网上百度下载下来就可以啦嘻嘻,小颖就把default.css和index.html文件粘贴出来哦. default.css * { margin: 0; pad

mui 框架中结合mui.ajax实现 下拉刷新和上拉加载功能

实现方式与之前写的jquery weui 下拉刷新和上拉加载功能有点相似,以下是实现过程! 后台返回的数据格式: 页面代码布局: <header id="header" class="mui-bar mui-bar-nav"> <h1 class="mui-title">订单列表</h1> <a class="mui-icon mui-pull-right iconfont icon-tuich

MUI 选项卡切换+下拉刷新动态 完整实现一例

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Hello MUI</title> <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no"> <

uni-app下拉刷新加载刷新数据

onPullDownRefresh 监听该页面用户下拉刷新事件 需要在 pages.json 里 开启 enablePullDownRefresh "globalStyle": { } 当处理完数据刷新后,uni.stopPullDownRefresh 可以停止当前页面的下拉刷新 uni.startPullDownRefresh(OBJECT) success Function 否 接口调用成功的回调 fail Function 否 接口调用失败的回调函数 complete Funct

小程序-下拉刷新

框架---小程序配置---页面配置 属性 类型 默认值 说明 enablePullDownRefresh boolean false 是否开启当前页面下拉刷新 onReachBottomDistance number 50 页面上拉触底事件触发时距页面底部距离(px) 如果是全局都需要下拉刷星,在app.json中配置: { "window":{ "enablePullDownRefresh":true } } 如果是指定页面(detail.wxml)需要下拉刷新,

mui的下拉刷新和上拉加载

代码定义: var refresh = function(){ mui.init({ pullRefresh : { container:'#refreshContainer',//下拉刷新容器标识,querySelector能定位的css选择器均可,比如:id..class等 down : { height:50,//可选,默认50.触发下拉刷新拖动距离, auto: false,//可选,默认false.自动下拉刷新一次 contentdown : "下拉可以刷新",//可选,在下

基于Android的计步器(Pedometer)的讲解(六)——ListView下拉刷新页面

计步器(Pedometer)整个项目的源代码,最近做了比较大的修改,可能以前下载的不能运行,感兴趣的朋友可以下载来看看(记得帮小弟在github打个星~) https://github.com/296777513/pedometer 今天实现实现的下拉刷新的功能,先上几张效果图: 如图所示,今天就是要实现的这个效果 首先,分析ListView下拉刷新实现方式 1.需要添加顶部下拉加载页面 2.需要监听onScrollListener来判断当前是否显示在listview的最顶部 3.因为顶部下拉加

使用MUI框架,模拟手机端的下拉刷新,上拉加载操作。

套用mui官方文档的一句话:"开发者只需关心业务逻辑,实现加载更多数据即可".真的是不错的框架. 想更多的了解这个框架:http://dev.dcloud.net.cn/mui/ 那么如何实现上拉刷新,下拉加载的功呢? 首先需要一个容器: 1 <!--下拉刷新容器--> 2 <div id="refreshContainer" class="mui-content mui-scroll-wrapper"> 3 <di

Vue-上拉加载与下拉刷新(mint-ui:loadmore)一个页面使用多个上拉加载后冲突问题

所遇问题: 该页面为双选项卡联动,四个部分都需要上拉加载和下拉刷新功能,使用的mint-ui的loadmore插件,分别加上上拉加载后,只有最后一个的this.$refs.loadmore.onTopLoaded();和this.$refs.loadmore.onBottomLoaded(); 有效,其他的三个都无效,这两句话是意思是查询完要调用一次,用于重新定位 分析原因: 首先这四个模块都是用的 <mt-loadmore :top-method="loadTop" :bott