-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtouch.js
More file actions
29 lines (24 loc) · 858 Bytes
/
touch.js
File metadata and controls
29 lines (24 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
var touch = {};
$dailogContent.on('touchstart',function (event) {
//起点的Y值
touches.startY = event.targetTouches[0].pageY;
//起点距顶部距离
touches.current = $content[0].scrollTop;
//开始的毫秒数
touches.startTime = new Date().getTime();
}).on('touchmove',function (event) {
//跟手滚动
$content[0].scrollTop = (touches.startY - event.targetTouches[0].pageY) + touches.current;
}).on('touchend',function (event) {
// 手指离开后,模拟缓动
var endTime = new Date().getTime(),
endPos = changedTouches[0].pageY,
ratio = (endPos - touches.startY) / (endTime - touches.startTime),
slowmoving = ratio * 180,
curPos = $content[0].scrollTop;
if (Math.abs(ratio) > 0.5){
animation(400, function(process){
$content[0].scrollTop = curPos - slowmoving * process;
});
}
})