Created
February 18, 2018 19:30
-
-
Save thheller/9ec47a878a2332317fe2d897c6d2cb2b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var raf = require('rafl') | |
var E_NOSCROLL = new Error('Element already at target scroll position') | |
var E_CANCELLED = new Error('Scroll cancelled') | |
var min = Math.min | |
module.exports = { | |
left: make('scrollLeft'), | |
top: make('scrollTop') | |
} | |
function make (prop) { | |
return function scroll (el, to, opts, cb) { | |
if (typeof opts == 'function') cb = opts, opts = {} | |
if (typeof cb != 'function') cb = noop | |
var start = +new Date | |
var from = el[prop] | |
var ease = opts.ease || inOutSine | |
var duration = !isNaN(opts.duration) ? +opts.duration : 350 | |
var cancelled = false | |
return from === to ? | |
cb(E_NOSCROLL, el[prop]) : | |
raf(animate), cancel | |
function cancel () { | |
cancelled = true | |
} | |
function animate (timestamp) { | |
if (cancelled) return cb(E_CANCELLED, el[prop]) | |
var now = +new Date | |
var time = min(1, ((now - start) / duration)) | |
var eased = ease(time) | |
el[prop] = (eased * (to - from)) + from | |
time < 1 ? raf(animate) : raf(function () { | |
cb(null, el[prop]) | |
}) | |
} | |
} | |
} | |
function inOutSine (n) { | |
return 0.5 * (1 - Math.cos(Math.PI * n)) | |
} | |
function noop () {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
shadow$provide.module$node_modules$scroll$index = function(a, c, f, b) { | |
function e(a, k, c, d, b) { | |
function h(d) { | |
if (p) return b(Error("Scroll cancelled"), k[a]); | |
d = Math.min(1, (+new Date() - f) / m); | |
var g = n(d); | |
k[a] = g * (c - e) + e; | |
1 > d | |
? l(h) | |
: l(function() { | |
b(null, k[a]); | |
}); | |
} | |
var f = +new Date(), | |
e = k[a], | |
p = !1, | |
n = g, | |
m = 350; | |
"function" === typeof d | |
? (b = d) | |
: ((d = d || {}), | |
(n = d.ease || n), | |
(m = d.duration || m), | |
(b = b || function() {})); | |
if (e === c) | |
return b(Error("Element already at target scroll position"), k[a]); | |
l(h); | |
return function() { | |
p = !0; | |
}; | |
} | |
function g(a) { | |
return 0.5 * (1 - Math.cos(Math.PI * a)); | |
} | |
var l = c("module$node_modules$rafl$index"); | |
f.exports = { | |
top: function(a, b, c, d) { | |
return e("scrollTop", a, b, c, d); | |
}, | |
left: function(a, b, c, d) { | |
return e("scrollLeft", a, b, c, d); | |
} | |
}; | |
}; | |
//# sourceMappingURL=module$node_modules$scroll$index.js.map |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment