@@ -22,43 +22,28 @@ const ScrollScreen = {
2222 this . toHeight = - 1 ;
2323 this . num = 0 ;
2424 // this.currentNum = 0;
25- [ 'raf' , 'cancelRequestAnimationFrame' , 'onWheel' , 'startScroll' ]
25+ [ 'raf' , 'cancelRequestAnimationFrame' , 'onWheel' , 'startScroll' , 'isScroll' ]
2626 . forEach ( ( method ) => this [ method ] = this [ method ] . bind ( this ) ) ;
2727 EventListener . addEventListener ( 'wheel.scrollWheel' , this . onWheel ) ;
28- EventListener . addEventListener ( 'scroll.scrollScreen' , this . scrollEvent ) ;
2928 // 刚进入时滚动条位置
30- // requestAnimationFrame(this.startScroll)
3129 setTimeout ( this . startScroll ) ;
3230 } ,
33- scrollEvent ( ) {
34- const _mapped = mapped . getMapped ( ) ;
35- const _arr = _mapped . __arr ;
36- this . scrollTop = currentScrollTop ( ) ;
37- _arr . forEach ( ( str , i ) => {
38- const dom = _mapped [ str ] ;
39- const domOffsetTop = dom . offsetTop ;
40- const domHeight = dom . getBoundingClientRect ( ) . height ;
41- if ( this . scrollTop >= domOffsetTop && this . scrollTop < domOffsetTop + domHeight ) {
42- this . currentNum = i ;
43- }
44- } ) ;
45- } ,
31+
4632 startScroll ( ) {
4733 const _mapped = mapped . getMapped ( ) ;
4834 const _arr = _mapped . __arr ;
4935 if ( ! _arr . length ) {
5036 EventListener . removeEventListener ( 'wheel.scrollWheel' , this . onWheel ) ;
5137 return ;
5238 }
53- this . scrollTop = window . pageYOffset ;
39+ this . scrollTop = currentScrollTop ( ) ;
5440 _arr . forEach ( ( str , i ) => {
5541 const dom = _mapped [ str ] ;
5642 const domOffsetTop = dom . offsetTop ;
5743 const domHeight = dom . getBoundingClientRect ( ) . height ;
5844 if ( this . scrollTop >= domOffsetTop && this . scrollTop < domOffsetTop + domHeight ) {
5945 this . num = i ;
6046 this . toHeight = domOffsetTop ;
61- // this.currentNum = this.num;
6247 }
6348 } ) ;
6449 // 如果 toHeight === -1 且 this.scrollTop 有值时;
@@ -69,7 +54,6 @@ const ScrollScreen = {
6954 const tooNum = Math . ceil ( ( this . scrollTop - endDom . offsetTop -
7055 endDom . getBoundingClientRect ( ) . height ) / windowHeight ) ;
7156 this . num = mapped . getMapped ( ) . __arr . length + tooNum ;
72- // this.currentNum = this.num;
7357 }
7458 return ;
7559 }
@@ -100,15 +84,35 @@ const ScrollScreen = {
10084 requestAnimationFrame . cancel ( this . rafID ) ;
10185 this . rafID = - 1 ;
10286 } ,
87+ getComputedStyle ( dom ) {
88+ return document . defaultView ? document . defaultView . getComputedStyle ( dom ) : { } ;
89+ } ,
90+ isScroll ( dom ) {
91+ const style = this . getComputedStyle ( dom ) ;
92+ const overflow = style . overflow ;
93+ const overflowY = style . overflowY ;
94+ const isScrollOverflow = overflow === 'auto' || overflow === 'scroll' || overflow === 'overlay'
95+ || overflowY === 'auto' || overflowY === 'scroll' || overflowY === 'overlay' ;
96+ if ( dom === document . body ) {
97+ return false ;
98+ } else if ( dom . scrollHeight > dom . offsetHeight
99+ && isScrollOverflow
100+ && dom . scrollTop < dom . scrollHeight ) {
101+ return true ;
102+ }
103+ return this . isScroll ( dom . parentNode ) ;
104+ } ,
103105 onWheel ( e ) {
104106 const _mapped = mapped . getMapped ( ) ;
105107 if ( ! _mapped . __arr . length ) {
106108 EventListener . removeEventListener ( 'wheel.scrollWheel' , this . onWheel ) ;
107109 return ;
108110 }
111+ if ( this . isScroll ( e . target ) ) {
112+ return ;
113+ }
109114 const deltaY = e . deltaY ;
110115 e . preventDefault ( ) ;
111- // console.log(e.wheelDelta,e.deltaY)
112116 if ( this . rafID === - 1 && deltaY !== 0 && this . toHeight === - 1 ) {
113117 // 如果滚动条托动过了,需要获取当前的num;
114118 const _arr = _mapped . __arr ;
@@ -165,14 +169,13 @@ const ScrollScreen = {
165169 windowHeight * ( this . num - mapped . getMapped ( ) . __arr . length ) : this . toHeight ;
166170 this . toHeight = this . toHeight < 0 ? 0 : this . toHeight ;
167171 this . toHeight = this . toHeight > docHeight - windowHeight ?
168- docHeight - windowHeight : this . toHeight ;
172+ ( docHeight - windowHeight ) : this . toHeight ;
169173 this . rafID = requestAnimationFrame ( this . raf ) ;
170- // this.currentNum = this.num;
174+ this . currentNum = this . num ;
171175 }
172176 } ,
173177 unMount ( ) {
174178 EventListener . removeEventListener ( 'wheel.scrollWheel' , this . onWheel ) ;
175- EventListener . removeEventListener ( 'scroll.scrollScreen' , this . scrollEvent ) ;
176179 } ,
177180} ;
178181export default {
0 commit comments