博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
手机端触屏滚动效果
阅读量:4485 次
发布时间:2019-06-08

本文共 5778 字,大约阅读时间需要 19 分钟。

因为现在做的项目在手机上的,而使用 overflow: scroll;用自带的滚动效果在IOS的手机上很卡不知道什么原因,同事建议自己写一个这样的效果来解决,所以找了下资料自己弄了下目前效果还不知道这么样先贴上来备份一下不知道项目中要不要改!!!

html

  
test
服务条款

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人撒旦哈萨克的哈萨克觉得哈萨克觉得很我们是好人好人

返回
确定

js:

function TouchScroll(obj){    this.frd = document.getElementById(obj.frd),    this.ID = document.getElementById(obj.ID),    this.timer = obj.timer,    this.lastY = 0,    this.startY = 0,    this.height = 0,    this.sTop = 0,    this.scrollHeight = this.ID.clientHeight - this.frd.clientHeight,    this.frdHeight = this.frd.clientHeight,    this.conHeight = this.ID.clientHeight,    this.lastMoveTime = 0,//一下是缓动参数    this.lastMoveStart = 0,    stopInertiaMove = false;//停止缓动滚动    this.init();}TouchScroll.prototype={    init: function(){        var that = this;        that.ID.addEventListener('touchstart', function(e){            that.start(e);        });        that.ID.addEventListener('touchmove', function(e){            that.move(e);        });        that.ID.addEventListener('touchend', function(e){            that.end(e);        });    },    start: function(e){        var that = this;        document.addEventListener('touchmove',function(ev){            ev.preventDefault();        });        that.lastY = that.startY = e.targetTouches[0].pageY;        //下面是缓动        that.lastMoveStart = that.lastY;        that.lastMoveTime = Date.now();        that.stopInertiaMove = true;    },    move: function(e){        var that = this;        var nowY = e.targetTouches[0].pageY;        var changeY = nowY - that.lastY;        that.sTop = parseInt(that.ID.style.top) + changeY        if (that.sTop >= 0) {that.sTop = 0}else if(Math.abs(that.sTop) > that.scrollHeight){            console.log(-(that.scrollHeight));            that.sTop = -(that.scrollHeight);        };        that.ID.style.top = that.sTop + "px";        //console.log(this.frd.style.top);        that.lastY = nowY;        //下面是缓动        var nowTime = Date.now();        that.stopInertiaMove = true;        if(nowTime - that.lastMoveTime >300){            that.lastMoveTime = nowTime;            that.lastMoveStart = that.lastY;        }    },    end: function(e){        var that = this;        document.removeEventListener('touchmove',function(ev){            ev.preventDefault();        });        var nowY = e.changedTouches[0].pageY;//touchend事件不存在targetTouches和touches        var changeY = nowY - this.lastY;        var contentY = parseInt(this.ID.style.top) + changeY;        this.ID.style.top = contentY + "px";        this.lastY = nowY;        //下面缓动        var nowTime = Date.now();        var v = (nowY - that.lastMoveStart)/(nowTime - that.lastMoveTime);//最后一划平均速度        console.log(v)        that.stopInertiaMove = false;        (function(v,startTime,contentY){            var updown = v>0?-1 :1;//加速度方向正数向上,负数向下            var everyidle =  updown*0.0006;//每次消耗时间            var tozerotime = v/everyidle;//速度到0需要多少时间(多少次)            var distance = v * tozerotime / 2;//移动距离(缓动变慢至0距离减半)            function inertiaMove(){                if (that.stopInertiaMove) {
return}; var theTime = Date.now(); var t = theTime - startTime;//缓动时间差 var nowV = v + t*everyidle; console.log(t+'时间') console.log(updown+'方向'); console.log(nowV+'变化后距离'); console.log(everyidle+'每次消耗'); console.log(updown*nowV+'判断结束') // 速度方向变化表示速度达到0了 if (updown*nowV > 0) { console.log('速度到0结束') return; } var moveY = (v + nowV)/2 * t;//每次在时间内的平均速度乘以时间得到移动距离 that.ID.style.top = (contentY + moveY) + "px"; console.log(contentY + moveY); setTimeout(inertiaMove, 10); } inertiaMove(); })(v,nowTime,contentY)//nowTime是触发end的时间作为缓动开始时间 }}window.TouchScroll = TouchScroll;

 

转载于:https://www.cnblogs.com/lichuntian/p/6103866.html

你可能感兴趣的文章
ScanTailor-ScanTailor 自动矫正图像歪斜
查看>>
UVA GCD - Extreme (II)
查看>>
完成个人中心—导航标签
查看>>
【C++】C++中变量的声明与定义的区别
查看>>
前端性能优化
查看>>
static
查看>>
属性动画
查看>>
Hadoop集群时钟同步
查看>>
C++二维数组讲解、二维数组的声明和初始化
查看>>
纹理映射和混合
查看>>
PHP获取域名、IP地址的方法
查看>>
php验证复选框的小例子
查看>>
Sql Server 判断表或数据库是否存在
查看>>
计算机网络
查看>>
iOS-浅谈runtime运行时机制
查看>>
数字证书原理 - 转自 http://www.cnblogs.com/JeffreySun/archive/2010/06/24/1627247.html
查看>>
关于float和margin
查看>>
Python练习-内置函数的应用
查看>>
洛谷P3905 道路重建
查看>>
数据表格 - DataGrid - 行编辑
查看>>