zoukankan      html  css  js  c++  java
  • 引用iscroll的一个封装方法

    var Page = function(cid, data,callback) {
    var _self = this;
    var cid = $(cid);
    var currPage=1;
    // 下拉上拉加载数据
    var myScroll, pullDownEl, pullDownOffset, pullUpEl, pullUpOffset, generatedCount = 0;
    this.query = function(curr) {
    if(curr){
    currPage=curr;
    }
    data["PAGE_INFO.currentPage"]=currPage;
    if(!myScroll){loaded();}
    PAjax({
    data : data,
    success : function(json) {
    $('#loading').hide();
    if (isEmpty(json.MSG)) {
    currPage++;
    var list = json.PAGE_LIST;
    _self.addBillHtml(list);
    myScroll.refresh();
    } else {
    _alert(json.MSG, "", function() {
    var html = '<li class="listCenter">数据加载失败!</li>';
    $(cid).append(html);
    });
    }
    }
    });
    }
    this.refresh=function(){
    cid.empty();
    _self.query(1);
    }
    this.addBillHtml = function(list) {
    if (list && list.length > 0) {
    var htmls = [];
    $.each(list, function() {
    var html = callback(cid, this);
    htmls.push(html);
    })
    cid.append(htmls);
    } else {
    $("#pullUp").hide();
    $(".endList").show();
    }
    ;
    myScroll.refresh();
    }
    this.iScrollClick = function() {
    if (/iPhone|iPad|iPod|Macintosh/i.test(navigator.userAgent))
    return false;
    if (/Chrome/i.test(navigator.userAgent))
    return (/Android/i.test(navigator.userAgent));
    if (/Silk/i.test(navigator.userAgent))
    return false;
    if (/Android/i.test(navigator.userAgent)) {
    var s = navigator.userAgent.substr(navigator.userAgent
    .indexOf('Android') + 8, 3);
    return parseFloat(s[0] + s[3]) < 44 ? false : true
    }
    }

    // 初始化iScroll控件
    function loaded() {
    pullDownEl = document.getElementById('pullDown');
    pullDownOffset = pullDownEl.offsetHeight;
    pullUpEl = document.getElementById('pullUp');
    pullUpOffset = pullUpEl.offsetHeight;
    myScroll = new iScroll(
    'wrapper',
    {
    scrollbarClass : 'myScrollbar', /* 重要样式 */
    useTransition : false, /* 此属性不知用意,本人从true改为false */
    topOffset : pullDownOffset,
    onRefresh : function() {
    if (pullDownEl.className.match('loading')) {
    pullDownEl.className = '';
    //pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
    } else if (pullUpEl.className.match('loading')) {
    pullUpEl.className = '';
    pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
    }
    },
    onScrollMove : function() {
    /*if (this.y > 5 && !pullDownEl.className.match('flip')) {
    pullDownEl.className = 'flip';
    pullDownEl.querySelector('.pullDownLabel').innerHTML = '松手开始更新...';
    this.minScrollY = 0;
    } else if (this.y < 5
    && pullDownEl.className.match('flip')) {
    pullDownEl.className = '';
    pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
    this.minScrollY = -pullDownOffset;
    } else */
    if (this.y<0 && this.y < (this.maxScrollY - 5)
    && !pullUpEl.className.match('flip')) {
    pullUpEl.className = 'flip';
    pullUpEl.querySelector('.pullUpLabel').innerHTML = '释放立即加载...';
    this.maxScrollY = this.maxScrollY;
    } else if (this.y<0 && this.y > (this.maxScrollY + 5)
    && pullUpEl.className.match('flip')) {
    pullUpEl.className = '';
    pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
    this.maxScrollY = pullUpOffset;
    }
    },
    onScrollEnd : function() {
    if (pullDownEl.className.match('flip')) {
    //pullDownEl.className = 'loading';
    // pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';
    // pullDownAction(); // Execute custom function
    // (ajax call?)
    } else if (pullUpEl.className.match('flip')) {
    pullUpEl.className = 'loading';
    pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
    // pullUpAction(); // Execute custom function (ajax
    // call?)
    _self.query();
    }
    }
    });

    setTimeout(function() {
    document.getElementById('wrapper').style.left = '0';
    }, 800);
    }
    // 初始化绑定iScroll控件
    /*document.addEventListener('touchmove', function(e) {
    e.preventDefault();
    }, false);*/
    document.addEventListener('DOMContentLoaded', loaded, false);

    }

    引用

    page=new Page(tabs,data,addRow);
    page.query();

  • 相关阅读:
    分享我的2014年3月unity3d面试题与参考答案(转)
    Unity3D 面试ABC
    MiniJson解释Json字符串
    Unity3D研究之支持中文与本地文件的读取写入(转)
    unity3d--NGUI制作中文字体
    吊炸天之十步完全理解SQL
    mysql主从同步碰到的问题
    Redis 安装碰到问题
    在Centos系统下使用命令安装gnome图形界面程序
    centos7 网络问题
  • 原文地址:https://www.cnblogs.com/smght/p/5163248.html
Copyright © 2011-2022 走看看