$(function(){
var iosScroll,
startY,
endY,
startTime,
endTime,
speed,
distance,
duration,
interval,
a=3,
timer=null,
//-1为下,1为上
flag;
$('#container').on('touchstart',function(e){
startTime=(new Date()).getTime();
startY=e.originalEvent.changedTouches[0].clientY;
});
$('#container').on('touchend',function(e){
var agent = navigator.userAgent,
_isAndroid = /(Android)/i.test(agent),
_isiOS = /(iPhone|iPad|iPod|iOS)/i.test(agent) && !_isAndroid;
if(_isiOS){
clearInterval(timer);
var a=1000;
var dir=-1;
endTime=(new Date()).getTime();
endY=e.originalEvent.changedTouches[0].clientY;
Speed();
interval=(endTime-startTime)/1000;
// duration,匀减速运动的时间,distance,匀减速运动的距离,V,初始速度
var v=Math.abs(speed);
duration=Math.abs(v/a).toFixed(2);
distance=v*duration/2;
var top=$(this).scrollTop();
var me=this,count=1;
timer=setInterval(function(){
var nowTime = (new Date()).getTime();
var t = (nowTime-endTime)/1000;
var nowV = v + t*a*dir;
var moveY =nowV*10/1000;
me.scrollTop+=moveY*flag;
if(nowV<0){
clearInterval(timer);
}
},10);
}
});
function Speed(){
speed=(startY-endY)/((startTime-endTime)/1000);
speed=speed>0?Math.ceil(speed):Math.floor(speed);
speed<0?flag=1:flag=-1;
}
})
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
ringa_lee