Skip to content

Commit fc73d7e

Browse files
committed
2 parents f23320d + b6d1b9b commit fc73d7e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/index.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import animate from 'amator'
22

3-
export default function (elem, centerIfNeeded, options, finalElement) {
3+
export default function (elem, centerIfNeeded, options, finalElement, config) {
44

55
if (!elem) throw new Error('Element is required in scrollIntoViewIfNeeded')
66

@@ -12,16 +12,21 @@ export default function (elem, centerIfNeeded, options, finalElement) {
1212
}
1313
}
1414

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+
1520
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
1823
, "translate":
1924
function (x, y) {
20-
return makeArea(x + left, y + top, width, height);
25+
return makeArea(x + left + offsetLeft, y + top + offsetTop, width, height);
2126
}
2227
, "relativeFromTo":
2328
function (lhs, rhs) {
24-
var newLeft = left, newTop = top;
29+
var newLeft = left + offsetLeft, newTop = top + offsetTop;
2530
lhs = lhs.offsetParent;
2631
rhs = rhs.offsetParent;
2732
if (lhs === rhs) {

0 commit comments

Comments
 (0)