Skip to content

Prevents calling jump() while current jump is in progress #69

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions src/jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const jumper = () => {

let start // where scroll starts (px)
let stop // where scroll stops (px)
let scrolling // scrolling state (boolean)

let offset // adjustment from the stop position (px)
let easing // easing function (function)
Expand Down Expand Up @@ -61,6 +62,8 @@ const jumper = () => {
// scroll finished helper

function done () {
scrolling = false

// account for rAF time rounding inaccuracies
window.scrollTo(0, start + distance)

Expand All @@ -85,6 +88,11 @@ const jumper = () => {
// API

function jump (target, options = {}) {
if (scrolling) {
return
}
scrolling = true

// resolve options, or use defaults
duration = options.duration || 1000
offset = options.offset || 0
Expand Down