@@ -2,14 +2,15 @@ import { debounce, bind } from 'decko';
2
2
import { EventEmitter } from 'eventemitter3' ;
3
3
4
4
import { querySelector , isBrowser } from '../utils' ;
5
+ import { RedocNormalizedOptions } from './RedocNormalizedOptions' ;
5
6
6
7
const EVENT = 'scroll' ;
7
8
8
9
export class ScrollService {
9
10
private _scrollParent : Window | HTMLElement | undefined ;
10
11
private _emiter : EventEmitter ;
11
12
private _prevOffsetY : number = 0 ;
12
- constructor ( ) {
13
+ constructor ( private options : RedocNormalizedOptions ) {
13
14
this . _scrollParent = isBrowser ? window : undefined ;
14
15
this . _emiter = new EventEmitter ( ) ;
15
16
this . bind ( ) ;
@@ -37,12 +38,12 @@ export class ScrollService {
37
38
38
39
isElementBellow ( el : Element | null ) {
39
40
if ( el === null ) return ;
40
- return el . getBoundingClientRect ( ) . top > 0 ;
41
+ return el . getBoundingClientRect ( ) . top > this . options . scrollYOffset ( ) ;
41
42
}
42
43
43
44
isElementAbove ( el : Element | null ) {
44
45
if ( el === null ) return ;
45
- return Math . trunc ( el . getBoundingClientRect ( ) . top ) <= 0 ;
46
+ return Math . trunc ( el . getBoundingClientRect ( ) . top ) <= this . options . scrollYOffset ( ) ;
46
47
}
47
48
48
49
subscribe ( cb ) : ( ) => void {
@@ -55,6 +56,9 @@ export class ScrollService {
55
56
return ;
56
57
}
57
58
element . scrollIntoView ( ) ;
59
+ this . _scrollParent &&
60
+ this . _scrollParent . scrollBy &&
61
+ this . _scrollParent . scrollBy ( { top : - this . options . scrollYOffset ( ) } ) ;
58
62
}
59
63
60
64
scrollIntoViewBySelector ( selector : string ) {
0 commit comments