-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrag.js
48 lines (43 loc) · 865 Bytes
/
drag.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
/**
* Author:Toti
* Mail:mr.totihuang@gmail.com
*/
/**
* 拖动函数
* @param {evt} evt
*/
export function dragger(evt) {
var dragging = null;
var target = evt.target;
switch (evt.type) {
case "mousedown":
if (target.className.indexOf("draggable") > -1) {
dragging = target;
}
break;
case "mousemove":
dragging.style.left = evt.clientX + "px";
dragging.style.top = evt.clientY + "px";
break;
case "mouseup":
dragging = null;
break;
default:
break;
}
}
/**
* 数组分块模式
* @param {array} array
* @param {function} process
* @param {object} context
*/
export function chunk(array, process, context) {
setTimeout(function fn() {
var item = array.shift();
process(item);
if (array.length > 0) {
setTimeout(fn, 100);
}
}, 100);
}