File tree Expand file tree Collapse file tree 2 files changed +29
-10
lines changed
Expand file tree Collapse file tree 2 files changed +29
-10
lines changed Original file line number Diff line number Diff line change 11import { getEventPath , stopAndPrevent } from './event.js'
2- import { hasScrollbar } from './scroll.js'
2+ import { hasScrollbar , hasScrollbarX } from './scroll.js'
33import Platform from '../plugins/platform.js'
44
55let registered = 0
@@ -15,19 +15,26 @@ function shouldPreventScroll (e) {
1515 return true
1616 }
1717
18- if ( Math . abs ( e . deltaX ) > Math . abs ( e . deltaY ) ) {
19- return false
20- }
21-
22- const path = getEventPath ( e )
18+ const
19+ path = getEventPath ( e ) ,
20+ scrollY = Math . abs ( e . deltaX ) <= Math . abs ( e . deltaY ) ,
21+ testFn = scrollY ? hasScrollbar : hasScrollbarX
2322
2423 for ( let index = 0 ; index < path . length ; index ++ ) {
2524 const el = path [ index ]
2625
27- if ( hasScrollbar ( el ) ) {
28- return e . deltaY < 0 && el . scrollTop === 0
29- ? true
30- : e . deltaY > 0 && el . scrollTop + el . clientHeight === el . scrollHeight
26+ if ( testFn ( el ) ) {
27+ return scrollY
28+ ? (
29+ e . deltaY < 0 && el . scrollTop === 0
30+ ? true
31+ : e . deltaY > 0 && el . scrollTop + el . clientHeight === el . scrollHeight
32+ )
33+ : (
34+ e . deltaX < 0 && el . scrollLeft === 0
35+ ? true
36+ : e . deltaX > 0 && el . scrollLeft + el . clientWidth === el . scrollWidth
37+ )
3138 }
3239 }
3340
Original file line number Diff line number Diff line change @@ -108,6 +108,18 @@ export function hasScrollbar (el) {
108108 )
109109}
110110
111+ export function hasScrollbarX ( el ) {
112+ if ( ! el || el . nodeType !== Node . ELEMENT_NODE ) {
113+ return false
114+ }
115+
116+ return el . scrollWidth > el . clientWidth && (
117+ el . classList . contains ( 'scroll' ) ||
118+ el . classList . contains ( 'overflow-auto' ) ||
119+ [ 'auto' , 'scroll' ] . includes ( window . getComputedStyle ( el ) [ 'overflow-x' ] )
120+ )
121+ }
122+
111123export default {
112124 getScrollTarget,
113125 getScrollHeight,
You can’t perform that action at this time.
0 commit comments