drag.js
1.4 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
44
45
46
47
48
49
50
51
function down(e) {
this.strX = e.pageX;
this.strY = e.pageY;
this.strL = this.offsetLeft;
this.strT = this.offsetTop;
if (this.setCapture) {
this.setCapture();
xdyEvent.on(tool, "mousemove", move);
xdyEvent.on(tool, "mouseup", up);
} else {
this.MOVE = xdyEvent.processThis(move, this);
this.UP = xdyEvent.processThis(up, this);
xdyEvent.on(document, "mousemove", this.MOVE);
xdyEvent.on(document, "mouseup", this.UP);
}
xdyEvent.fire.call(this, "xdyDragStart", e);
}
function move(e) {
var curL = e.pageX - this.strX + this.strL;
var curT = e.pageY - this.strY + this.strT;
var minL = 0, minT = 0, maxL = tabBox.offsetWidth-tool.offsetWidth, maxT = tabBox.offsetHeight-tool.offsetHeight;
curL = curL <= minL ? minL : (curL >= maxL ? maxL : curL);
curT = curT <= minT ? minT : (curT >= maxT ? maxT : curT);
this.style.left = curL + "px";
this.style.top = curT + "px";
xdyEvent.fire.call(this, "xdyDragMove", e);
}
function up(e) {
if (this.releaseCapture) {
this.releaseCapture();
$event.off(tool, "mousemove", move);
$event.off(tool, "mouseup", up);
} else {
$event.off(document, "mousemove", this.MOVE);
$event.off(document, "mouseup", this.UP);
}
xdyEvent.fire.call(this, "xdyDragEnd", e);
}