@@ -8,19 +8,32 @@ export default {
88 en : "Use this will turn the cursor into a scroller and use it again will return it back to normal." ,
99 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" ,
1010 } ,
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+ }
1321
1422 if ( document . onmousedown && document . onmouseup && document . onmousemove ) {
15- body . style . cursor = "auto" ;
23+ document . body . style . cursor = "auto" ;
1624 document . onmousedown = document . onmouseup = document . onmousemove = null ;
1725 alert ( "Scroll by dragging DISABLED" ) ;
1826 } else {
19- body . style . cursor = "all-scroll" ;
27+ document . body . style . cursor = "all-scroll" ;
2028 document . onmousedown = function ( e ) {
2129 if ( ( e && ! e . button ) || ( window . event && event . button & 1 ) ) {
2230 X = e . clientX ;
2331 Y = e . clientY ;
32+ target = e . target ;
33+ while ( ! isElementScrollable ( target ) && target . parentNode ) {
34+ target = target . parentNode ;
35+ }
36+ console . log ( target ) ;
2437 return false ;
2538 }
2639 } ;
@@ -32,7 +45,12 @@ export default {
3245 } ;
3346 document . onmousemove = function ( e ) {
3447 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+
3654 X = e . clientX ;
3755 Y = e . clientY ;
3856 return false ;
0 commit comments