-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.mobileScroll.js
More file actions
43 lines (35 loc) · 1.33 KB
/
jquery.mobileScroll.js
File metadata and controls
43 lines (35 loc) · 1.33 KB
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$.fn.mobileScroll = function(options) {
if (options == null)
options = { };
if (options.inertia == null)
options.inertia = true;
this.live("touchstart", function(event) {
$(this).clearQueue();
event.preventDefault();
var e = event.originalEvent.targetTouches[0];
$(this).data('startY', e.pageY);
$(this).data('scrollTop', $(this).scrollTop());
$(this).data('startX', e.pageX);
$(this).data('scrollLeft', $(this).scrollLeft());
$(this).data("t", Date.now());
}).live("touchmove", function(event) {
event.preventDefault();
var e = event.originalEvent.targetTouches[0];
var startX = $(this).data('startX');
var startY = $(this).data('startY');
var dx = startX - e.pageX;
var dy = startY - e.pageY;
$(this).scrollTop( $(this).data('scrollTop') + dy );
$(this).scrollLeft( $(this).data('scrollLeft') + dx );
var dt= Date.now() - $(this).data("t");
$(this).data("s", parseInt(1000*dy/dt));
return false;
});
if (!!options.inertia) {
this.live("touchend", function() {
var s = $(this).data("s");
$(this).animate({scrollTop: "+=" + s + "px", scrollLeft: "+=" + s + "px"}, 1000, "easeOutCirc");
});
}
return this;
};