1
1
import animate from 'amator'
2
2
3
- export default function ( elem , centerIfNeeded , options , finalElement ) {
3
+ export default function ( elem , centerIfNeeded , options , finalElement , config ) {
4
4
5
5
if ( ! elem ) throw new Error ( 'Element is required in scrollIntoViewIfNeeded' )
6
6
@@ -12,16 +12,21 @@ export default function (elem, centerIfNeeded, options, finalElement) {
12
12
}
13
13
}
14
14
15
+ const offsetTop = config . offsetTop || 0 ;
16
+ const offsetLeft = config . offsetLeft || 0 ;
17
+ const offsetBottom = config . offsetBottom || 0 ;
18
+ const offsetRight = config . offsetRight || 0 ;
19
+
15
20
function makeArea ( left , top , width , height ) {
16
- return { "left" : left , "top" : top , "width" : width , "height" : height
17
- , "right" : left + width , "bottom" : top + height
21
+ return { "left" : left + offsetLeft , "top" : top + offsetTop , "width" : width , "height" : height
22
+ , "right" : left + offsetLeft + width + offsetRight , "bottom" : top + offsetTop + height + offsetBottom
18
23
, "translate" :
19
24
function ( x , y ) {
20
- return makeArea ( x + left , y + top , width , height ) ;
25
+ return makeArea ( x + left + offsetLeft , y + top + offsetTop , width , height ) ;
21
26
}
22
27
, "relativeFromTo" :
23
28
function ( lhs , rhs ) {
24
- var newLeft = left , newTop = top ;
29
+ var newLeft = left + offsetLeft , newTop = top + offsetTop ;
25
30
lhs = lhs . offsetParent ;
26
31
rhs = rhs . offsetParent ;
27
32
if ( lhs === rhs ) {
0 commit comments