@@ -8,19 +8,32 @@ export default {
8
8
en : "Use this will turn the cursor into a scroller and use it again will return it back to normal." ,
9
9
vi : "Bấm vào sẽ biến con trỏ thành con lăn và bấm lại nó sẽ đưa con trỏ trở lại bình thường" ,
10
10
} ,
11
- onClick : async function ( ) {
12
- let X , Y ;
11
+ onClick : function ( ) {
12
+ let X , Y , target ;
13
+
14
+ function isElementScrollable ( element ) {
15
+ return (
16
+ element &&
17
+ ( element . scrollWidth > element . clientWidth ||
18
+ element . scrollHeight > element . clientHeight )
19
+ ) ;
20
+ }
13
21
14
22
if ( document . onmousedown && document . onmouseup && document . onmousemove ) {
15
- body . style . cursor = "auto" ;
23
+ document . body . style . cursor = "auto" ;
16
24
document . onmousedown = document . onmouseup = document . onmousemove = null ;
17
25
alert ( "Scroll by dragging DISABLED" ) ;
18
26
} else {
19
- body . style . cursor = "all-scroll" ;
27
+ document . body . style . cursor = "all-scroll" ;
20
28
document . onmousedown = function ( e ) {
21
29
if ( ( e && ! e . button ) || ( window . event && event . button & 1 ) ) {
22
30
X = e . clientX ;
23
31
Y = e . clientY ;
32
+ target = e . target ;
33
+ while ( ! isElementScrollable ( target ) && target . parentNode ) {
34
+ target = target . parentNode ;
35
+ }
36
+ console . log ( target ) ;
24
37
return false ;
25
38
}
26
39
} ;
@@ -32,7 +45,12 @@ export default {
32
45
} ;
33
46
document . onmousemove = function ( e ) {
34
47
if ( X || Y ) {
35
- window . scrollBy ( X - e . clientX , Y - e . clientY ) ;
48
+ // window.scrollBy(X - e.clientX, Y - e.clientY);
49
+ const deltaX = X - e . clientX ;
50
+ const deltaY = Y - e . clientY ;
51
+ target . scrollLeft += deltaX ;
52
+ target . scrollTop += deltaY ;
53
+
36
54
X = e . clientX ;
37
55
Y = e . clientY ;
38
56
return false ;
0 commit comments