-
Notifications
You must be signed in to change notification settings - Fork 4
/
dragger.js
44 lines (38 loc) · 919 Bytes
/
dragger.js
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
44
/**
* send events on drag
*/
function dragger(el) {
var self = this;
var dragging = false;
var x, y;
el.ontouchstart = el.onmousedown = function(e) {
dragging = true;
if (e.touches) {
var p = e.touches[0];
x = p.pageX;
y = p.pageY;
} else {
x = e.clientX;
y = e.clientY;
}
self.emit('startdrag', x, y);
};
el.ontouchmove = el.onmousemove = function(e) {
var xx, yy;
if(!dragging) return;
if (e.touches) {
var p = e.touches[0];
xx = p.pageX;
yy = p.pageY;
} else {
xx = e.clientX;
yy = e.clientY;
}
self.emit('move', xx - x, yy - y);
return false;
};
el.ontouchend = el.onmouseup = function(e) {
dragging = false;
};
}
dragger.prototype = new Event();