Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added step option #78

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/easing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

const easeInOutQuad = (t, b, c, d) => {
t /= d / 2
if (t < 1) return c / 2 * t * t + b
if (t < 1) return (c / 2) * t * t + b
t--
return -c / 2 * (t * (t - 2) - 1) + b
return (-c / 2) * (t * (t - 2) - 1) + b
}

export default easeInOutQuad
7 changes: 7 additions & 0 deletions src/jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const jumper = () => {
let next // next scroll position (px)

let callback // to call when done scrolling (function)
let step // to call when finish an step (function)

// scroll position helper

Expand All @@ -46,6 +47,11 @@ const jumper = () => {
// determine time spent scrolling so far
timeElapsed = timeCurrent - timeStart

if (step) {
stop = start + step()
distance = stop - start + offset
}

// calculate next scroll position
next = easing(timeElapsed, start, distance, duration)

Expand Down Expand Up @@ -91,6 +97,7 @@ const jumper = () => {
callback = options.callback // "undefined" is a suitable default, and won't be called
easing = options.easing || easeInOutQuad
a11y = options.a11y || false
step = options.step || null

// cache starting position
start = location()
Expand Down