111
jihongshun
8 天以前 0c741cdda7ef9935a20d3090dfea97e1ce8ae754
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
let isDragging = false;
 
export default function (ele, options) {
  const moveFun = function (event) {
    options?.drag?.(event);
  };
 
  const upFun = function (event) {
    document.removeEventListener('mousemove', moveFun);
    document.removeEventListener('mouseup', upFun);
    document.onselectstart = null;
    document.ondragstart = null;
 
    isDragging = false;
 
    options?.end?.(event);
  };
 
  ele.addEventListener('mousedown', function (event) {
    if (isDragging) return;
    document.onselectstart = () => false;
    document.ondragstart = () => false;
    document.addEventListener('mousemove', moveFun);
    document.addEventListener('mouseup', upFun);
 
    isDragging = true;
 
    options?.start?.(event);
  });
}