Skip to content
Permalink
Browse files

Make onClickScrollTo option accept a function, closes #6

  • Loading branch information...
vfeskov committed Nov 10, 2018
1 parent c406751 commit 42df127acd64148144d74135134e83d7ee0e4b90

Some generated files are not rendered by default. Learn more.

BIN +18 Bytes (100%) dist/vanilla-back-to-top.min.js.gz
Binary file not shown.
@@ -97,17 +97,18 @@ function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterat
}

function scrollUp() {
var scrollTo = typeof onClickScrollTo === 'function' ? onClickScrollTo() : onClickScrollTo;
var _window = window,
performance = _window.performance,
requestAnimationFrame = _window.requestAnimationFrame;

if (scrollDuration <= 0 || typeof performance === 'undefined' || typeof requestAnimationFrame === 'undefined') {
return setScrollTop(onClickScrollTo);
return setScrollTop(scrollTo);
}

var start = performance.now();
var initScrollTop = getScrollTop();
var pxsToScrollBy = initScrollTop - onClickScrollTo;
var pxsToScrollBy = initScrollTop - scrollTo;
requestAnimationFrame(step);

function step(timestamp) {
@@ -18,7 +18,7 @@
ease = inOutSine, // any one from https://www.npmjs.com/package/ease-component will do
id = 'back-to-top',
innerHTML = '<svg viewBox="0 0 24 24"><path d="M7.41 15.41L12 10.83l4.59 4.58L18 14l-6-6-6 6z"></path></svg>', // https://material.io/icons/#ic_keyboard_arrow_up
onClickScrollTo = 0, // px
onClickScrollTo = 0, // px, or a function returning number
scrollContainer = document.body, // or a DOM element, e.g., document.getElementById('content')
scrollDuration = 100, // ms
showWhenScrollTopIs = 1, // px
@@ -111,13 +111,14 @@
}

function scrollUp () {
const scrollTo = typeof onClickScrollTo === 'function' ? onClickScrollTo() : onClickScrollTo
const { performance, requestAnimationFrame } = window
if (scrollDuration <= 0 || typeof performance === 'undefined' || typeof requestAnimationFrame === 'undefined') {
return setScrollTop(onClickScrollTo)
return setScrollTop(scrollTo)
}
const start = performance.now()
const initScrollTop = getScrollTop()
const pxsToScrollBy = initScrollTop - onClickScrollTo
const pxsToScrollBy = initScrollTop - scrollTo

requestAnimationFrame(step)

0 comments on commit 42df127

Please sign in to comment.
You can’t perform that action at this time.