Skip to content

Commit 54bee43

Browse files
committed
abstract element offset logic
1 parent 3f57f60 commit 54bee43

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

dist/jump.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/jump.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ const jumper = () => {
2929
return window.scrollY || window.pageYOffset
3030
}
3131

32+
// element offset helper
33+
34+
function top(element) {
35+
return element.getBoundingClientRect().top + start
36+
}
37+
3238
// rAF loop helper
3339

3440
function loop(timeCurrent) {
@@ -102,14 +108,14 @@ const jumper = () => {
102108
// bounding rect is relative to the viewport
103109
case 'object':
104110
element = target
105-
stop = element.getBoundingClientRect().top + location()
111+
stop = top(element)
106112
break
107113

108114
// scroll to element (selector)
109115
// bounding rect is relative to the viewport
110116
case 'string':
111117
element = document.querySelector(target)
112-
stop = element.getBoundingClientRect().top + location()
118+
stop = top(element)
113119
break
114120
}
115121

0 commit comments

Comments
 (0)