isScroll代码

window.iScroll = (function(w,d){
    var isMobile = /mobile/gi.test(navigator.userAgent.toLowerCase());
    var events = isMobile ? {
        down: ‘touchstart‘,
        move: ‘touchmove‘,
        up: ‘touchend‘
    } : {
        down: ‘mousedown‘,
        move: ‘mousemove‘,
        up: ‘mouseup‘
    },x,y,x2,y2 = 0;
    function Scroll(o){
        this.d = (typeof o==‘object‘) ? o : d.querySelector(o);
        this.child = this.d.children[0];
        if(this.child.offsetHeight > this.d.offsetHeight ) this.init();
    };
    Scroll.prototype={
        init : function(){
            this.d.insertAdjacentHTML("beforeend", ‘<div class="scroll-bar"><span></span></div>‘);
            this.bind();
        },
        top : function(fn){
            this.topFn  = fn;
        },
        bottom : function(fn){
            this.bottomFn = fn;
        },
        resize : function(){
            //璁剧疆婊氬姩鏉′綅缃紝楂樺害
            this.childHeight = this.child.offsetHeight
            this.scrollHeight = this.childHeight - this.d.offsetHeight;
            this.bar = this.d.querySelector(‘.scroll-bar‘)
            this.barHeight = this.d.offsetHeight * this.d.offsetHeight / this.child.offsetHeight;
            this.bar.style.height = this.barHeight+‘px‘;
            this.bar.style[‘transform‘] =  this.bar.style[‘-webkit-transform‘] = ‘translate3d(0,‘+( +this.get3d(this.child)[1]/(this.d.offsetHeight - this.child.offsetHeight)*(this.d.offsetHeight - this.bar.offsetHeight) )+‘px,0)‘;
        },
        bind : function(){
            var that = this,off,late,timer,speed,endPage,moveLate = false,endFlag = false,translate = 0;
            this.d.addEventListener(events.down,down)
            this.resize();
            function down(e){
                off = true;
                clearInterval(timer);
                var ev = isMobile ? e.changedTouches[0] : e ;
                x = ev.pageX;
                y = endPage = ev.pageY;
                that.child.style[‘transition‘] = that.child.style[‘-webkit-transition‘] = ‘none‘;
                translate = +that.get3d(that.child)[1];
                speed = 0;
                d.addEventListener(events.move,move);
                d.addEventListener(events.up,up);
            };
            function move(e){
                var ev = isMobile ? e.changedTouches[0] : e ;
                e.preventDefault();
                x2 = ev.pageX;y2 = ev.pageY;
                late = +that.get3d(that.child)[1];
                speed = ev.pageY - endPage;
                endPage = ev.pageY;
                moveLate = Math.abs( y2 - y) > 10 ? true : false;
                var barLate = ( late/(that.d.offsetHeight - that.child.offsetHeight)*(that.d.offsetHeight - that.bar.offsetHeight) );
                if(late >= 0){
                    that.child.style[‘transform‘] = that.child.style[‘-webkit-transform‘] = ‘translate3d(0,‘+parseInt((y2-y+translate)/3)+‘px,0)‘;
                    that.bar.style[‘transform‘] =  that.bar.style[‘-webkit-transform‘] = ‘translate3d(0,0px,0)‘;
                    endFlag = true
                    return false;
                }else if(-late>=that.scrollHeight){
                    if(off){
                        y = ev.pageY;
                        off = false;
                    };
                    that.child.style[‘transform‘] = that.child.style[‘-webkit-transform‘] = ‘translate3d(0,‘+parseInt((y2-y)/3 - that.scrollHeight)+‘px,0)‘;
                    endFlag = true
                    return false;
                }else{
                    endFlag = false;
                    that.child.style[‘transform‘]  = that.child.style[‘-webkit-transform‘] = ‘translate3d(0,‘+parseInt(y2-y+translate)+‘px,0)‘;
                    that.bar.style[‘transform‘] = that.bar.style[‘-webkit-transform‘] = ‘translate3d(0,‘+(barLate)+‘px,0)‘;
                }

            };
            function up(e){
                var scales = +that.get3d(that.child)[1]
                d.removeEventListener(events.move,move);
                d.removeEventListener(events.up,up);
                if(moveLate && endFlag){
                    moveLate = false
                    that.d.addEventListener(‘transitionend‘,fn,false);
                    that.d.addEventListener(‘webkitTransitionEnd‘,fn,false);
                };

                function fn(ev){
                    if(+that.get3d(that.child)[1]==0){
                        that.topFn && that.topFn.call(that.d,scales,0);
                    }else{
                        that.bottomFn && that.bottomFn.call(that.d,scales,+that.get3d(that.child)[1]);
                    };
                    that.d.removeEventListener(‘transitionend‘,fn);
                    that.d.removeEventListener(‘webkitTransitionEnd‘,fn);
                };
                timer = setInterval(function(){
                    late = that.get3d(that.child)[1]*1;
                    barLate = ( late/(that.d.offsetHeight - that.child.offsetHeight)*(that.d.offsetHeight -  that.bar.offsetHeight) )
                    speed *= 0.95;
                    if( Math.floor(Math.abs( speed)) <=0){
                        clearInterval(timer);
                        if(late > 0){
                            setTrans(true);
                        }else if(-late>= that.scrollHeight){
                            setTrans(false);
                        };
                    }else{
                        if(late > 0){
                            setTrans(true);
                         }else if(-late>= that.scrollHeight){
                            setTrans(false);
                        }else{
                            that.child.style[‘transform‘] = that.child.style[‘-webkit-transform‘] = ‘translate3d(0,‘+parseInt(late + speed)+‘px,0)‘;
                             that.bar.style[‘transform‘] =  that.bar.style[‘-webkit-transform‘] = ‘translate3d(0,‘+(barLate )+‘px,0)‘;
                        };
                    };
                },13);
                function setTrans(a){
                    clearInterval(timer);
                    that.child.style[‘transition‘] =‘transform .5s cubic-bezier(0.1, 0.57, 0.1, 1)‘;
                    that.child.style[‘-webkit-transition‘] = ‘-webkit-transform .5s cubic-bezier(0.1, 0.57, 0.1, 1)‘;
                    if(a){
                        that.child.style[‘transform‘] = that.child.style[‘-webkit-transform‘] = ‘translate3d(0,0px,0)‘;
                        that.bar.style[‘transform‘] = that.bar.style[‘-webkit-transform‘] = ‘translate3d(0,0px,0)‘;
                    }else{
                        that.child.style[‘transform‘] = that.child.style[‘-webkit-transform‘] = ‘translate3d(0,‘+- that.scrollHeight+‘px,0)‘;
                        that.bar.style[‘transform‘] = that.bar.style[‘-webkit-transform‘] = ‘translate3d(0,‘+( that.d.offsetHeight -  that.bar.offsetHeight )+‘px,0)‘;
                    };
                };
                e.stopImmediatePropagation();
            };
        },
        get3d : function(obj){
            var str = this.getst(obj,‘transform‘) || this.getst(obj,‘WebkitTransform‘);
            var results = str.match(/matrix(?:(3d)\(-{0,1}\d+(?:, -{0,1}\d+)*(?:, (-{0,1}\d+))(?:, (-{0,1}\d+))(?:, (-{0,1}\d+)), -{0,1}\d+\)|\(-{0,1}\d+(?:, -{0,1}\d+)*(?:, (-{0,1}\d+))(?:, (-{0,1}\d+))\))/);
            if(!results) return [0, 0, 0];
            if(results[1] == ‘3d‘) return results.slice(2,5);
            results.push(0);
            return results.slice(5, 8);
        },
        getst : function (obj,attr){
            return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj,null)[attr];
        }
    };
    return Scroll;
})(window,document);
时间: 2024-10-13 01:55:40

isScroll代码的相关文章

错误和问题解决的成本

问题描写叙述 错误 数据收集 根本原因 版本号   组件:数据修复           在一个实际成本组织中,(平均,先进先出,后进先出) 一个或更 多的下面情况可能发生: 1.导航到物料成本历史表单上的数量信息,与现有量表单的数量不匹配的记录 2. 一些物料前期已计成本的数量与前面的事务处理历史表单的数量不匹配 3. 全部的库存值报表与事务处理值报表不匹配 4. 存货层次成本更新表单的总数量与现有量数量表单不匹配(只在先进先出/后进先出) 5.这些症状的不论什么一个意味着 MMT-CQL不匹配

LigerUI一个前台框架增、删、改asp.net代码的实现

先上代码:前台代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">

关于isScroll如何使用

isScroll是用原生javascript写的实现局部滚动的一个库,它不依赖任何第三方框架.设计的初衷是为了解决移动webkit系浏览器的区域滚动问题,兼容safari.chrome.firefox5+.opera11+.IE9+及其他webkit核心浏览器.现已更新到isScroll5. 我们采用官网(http://iscrolljs.com/)推荐的html结构来举例: 1 <div class="wrapper"> 2 <ul> 3 <li>

Xcode 快速开发 代码块 快捷键

Xcode的代码片段(Code Snippets)创建自定义的代码片段,当你重用这些代码片段时,会给你带来很大的方便. 常用的: 1.strong:@property (nonatomic,strong) <#Class#> *<#object#>;2.weak:@property (nonatomic,weak) <#Class#> *<#object#>;3.copy:@property (nonatomic,copy) NSString *<#s

solr分布式索引【实战一、分片配置读取:工具类configUtil.java,读取配置代码片段,配置实例】

1 private static Properties prop = new Properties(); 2 3 private static String confFilePath = "conf" + File.separator + "config.properties";// 配置文件目录 4 static { 5 // 加载properties 6 InputStream is = null; 7 InputStreamReader isr = null;

微信支付PHP SDK —— 公众号支付代码详解

在微信支付 开发者文档页面 下载最新的 php SDK http://mch.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=11_1 这里假设你已经申请完微信支付 1. 微信后台配置  如图 我们先进行测试,所以先把测试授权目录和 测试白名单添加上.测试授权目录是你要发起微信请求的哪个文件所在的目录. 例如jsapi 发起请求一般是jsapi.php所在目录 为测试目录,测试白名单即开发人员的微信号. 正式的支付授权目录不能和测试的一样否则会报错.不填

如何上传代码到github?

如何上传代码到github? 首先你需要一个github账号,所有还没有的话先去注册吧! https://github.com/ 我们使用git需要先安装git工具,这里给出下载地址,下载后一路直接安装即可: https://git-for-windows.github.io/ 1.进入Github首页,点击New repository新建一个项目  2.填写相应信息后点击create即可 Repository name: 仓库名称 Description(可选): 仓库描述介绍 Public,

自己写的代码会写了,还是太渣,复杂度什么的直接报表

原题目是这样子的,本人按照一贯的作风想得很简单 #include<iostream> using namespace std; void H(int n) { while (n > 1) { if (n % 2 == 0) //这一步把取余和除法弄混淆. { cout << n << " "; n = n / 2; } else { cout << n << " "; n = 3 * n + 1; }

category is in invalid format hint微信第三方平台将第三方提交的代码包提交审核出错

微信第三方平台通过接口https://api.weixin.qq.com/wxa/submit_audit?access_token=TOKEN将第三方提交的代码包提交审核时一直返回错误码85008的错误信息: category is in invalid format hint 查了半天是接口提交数据时json_encode时中文不能编码提交 将向微信的提交代码     $this->https_post($url,json_encode($postData)); 改为     $this->