-
Notifications
You must be signed in to change notification settings - Fork 34
/
jQuery.dragmove.js
executable file
·67 lines (40 loc) · 1.9 KB
/
jQuery.dragmove.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Plugin: jQuery.dragmove
// Source: github.com/nathco/jQuery.dragmove
// Author: Nathan Rutzky
// Update: 1.0
(function($) {
$.fn.dragmove = function() {
return this.each(function() {
var $document = $(document),
$this = $(this),
active,
startX,
startY;
$this.on('mousedown touchstart', function(e) {
active = true;
startX = e.originalEvent.pageX - $this.offset().left;
startY = e.originalEvent.pageY - $this.offset().top;
if ('mousedown' == e.type)
click = $this;
if ('touchstart' == e.type)
touch = $this;
if (window.mozInnerScreenX == null)
return false;
});
$document.on('mousemove touchmove', function(e) {
if ('mousemove' == e.type && active)
click.offset({
left: e.originalEvent.pageX - startX,
top: e.originalEvent.pageY - startY
});
if ('touchmove' == e.type && active)
touch.offset({
left: e.originalEvent.pageX - startX,
top: e.originalEvent.pageY - startY
});
}).on('mouseup touchend', function() {
active = false;
});
});
};
})(jQuery);