Skip to content

Commit

Permalink
fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
callmecavs committed Jan 8, 2017
1 parent b22d31a commit 8aab623
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
2 changes: 1 addition & 1 deletion src/easing.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

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
}
Expand Down
50 changes: 25 additions & 25 deletions src/jump.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ const jumper = () => {

// scroll position helper

function location() {
function location () {
return window.scrollY || window.pageYOffset
}

// element offset helper

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

// rAF loop helper

function loop(timeCurrent) {
function loop (timeCurrent) {
// store time scroll started, if not started already
if(!timeStart) {
if (!timeStart) {
timeStart = timeCurrent
}

Expand All @@ -54,18 +54,18 @@ const jumper = () => {

// check progress
timeElapsed < duration
? requestAnimationFrame(loop) // continue scroll loop
: done() // scrolling is done
? window.requestAnimationFrame(loop) // continue scroll loop
: done() // scrolling is done
}

// scroll finished helper

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

// if scrolling to an element, and accessibility is enabled
if(element && a11y) {
if (element && a11y) {
// add tabindex indicating programmatic focus
element.setAttribute('tabindex', '-1')

Expand All @@ -74,7 +74,7 @@ const jumper = () => {
}

// if it exists, fire the callback
if(typeof callback === 'function') {
if (typeof callback === 'function') {
callback()
}

Expand All @@ -84,59 +84,59 @@ const jumper = () => {

// API

function jump(target, options = {}) {
function jump (target, options = {}) {
// resolve options, or use defaults
duration = options.duration || 1000
offset = options.offset || 0
offset = options.offset || 0
callback = options.callback // "undefined" is a suitable default, and won't be called
easing = options.easing || easeInOutQuad
a11y = options.a11y || false
easing = options.easing || easeInOutQuad
a11y = options.a11y || false

// cache starting position
start = location()

// resolve target
switch(typeof target) {
switch (typeof target) {
// scroll from current position
case 'number':
element = undefined // no element to scroll to
a11y = false // make sure accessibility is off
stop = start + target
break
a11y = false // make sure accessibility is off
stop = start + target
break

// scroll to element (node)
// bounding rect is relative to the viewport
case 'object':
element = target
stop = top(element)
break
stop = top(element)
break

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

// resolve scroll distance, accounting for offset
distance = stop - start + offset

// resolve duration
switch(typeof options.duration) {
switch (typeof options.duration) {
// number in ms
case 'number':
duration = options.duration
break
break

// function passed the distance of the scroll
case 'function':
duration = options.duration(distance)
break
break
}

// start the loop
requestAnimationFrame(loop)
window.requestAnimationFrame(loop)
}

// expose only the jump method
Expand Down

0 comments on commit 8aab623

Please sign in to comment.