Skip to content

Commit

Permalink
abstract element offset logic
Browse files Browse the repository at this point in the history
  • Loading branch information
callmecavs committed Jul 16, 2016
1 parent 3f57f60 commit 54bee43
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dist/jump.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions src/jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ const jumper = () => {
return window.scrollY || window.pageYOffset
}

// element offset helper

function top(element) {
return element.getBoundingClientRect().top + start
}

// rAF loop helper

function loop(timeCurrent) {
Expand Down Expand Up @@ -102,14 +108,14 @@ const jumper = () => {
// bounding rect is relative to the viewport
case 'object':
element = target
stop = element.getBoundingClientRect().top + location()
stop = top(element)
break

// scroll to element (selector)
// bounding rect is relative to the viewport
case 'string':
element = document.querySelector(target)
stop = element.getBoundingClientRect().top + location()
stop = top(element)
break
}

Expand Down

0 comments on commit 54bee43

Please sign in to comment.