1
0
mirror of https://github.com/bigchaindb/site.git synced 2024-12-24 18:36:11 +01:00
site/_src/_assets/javascripts/bigchain/smoothscroll.js

59 lines
2.0 KiB
JavaScript
Raw Normal View History

2016-02-06 14:33:15 +01:00
//
// https://github.com/bendc/anchor-scroll/blob/master/scroll.min.js
//
document.addEventListener("DOMContentLoaded", function() {
var e = function() {
if ("scrollingElement" in document) return document.scrollingElement;
var a = document.documentElement,
b = a.scrollTop;
a.scrollTop = b + 1;
var c = a.scrollTop;
a.scrollTop = b;
return c > b ? a : document.body
}(),
g = function(a) {
var b = e.scrollTop;
if (2 > a.length) a = -b;
else if (a = document.querySelector(a)) {
a = a.getBoundingClientRect().top;
var c = e.scrollHeight - window.innerHeight;
a = b + a < c ? a : c - b
} else a = void 0;
if (a) return new Map([
["start", b],
["delta", a]
])
},
h = function(a) {
var b =
a.getAttribute("href"),
c = g(b);
if (c) {
var d = new Map([
["duration", 800]
]),
k = performance.now();
requestAnimationFrame(function l(a) {
d.set("elapsed", a - k);
a = d.get("duration");
var f = d.get("elapsed"),
g = c.get("start"),
h = c.get("delta");
e.scrollTop = Math.round(h * (-Math.pow(2, -10 * f / a) + 1) + g);
2017-03-28 14:22:01 +02:00
d.get("elapsed") < d.get("duration") ? requestAnimationFrame(l) : (null, null, b, e.scrollTop = c.get("start") + c.get("delta"))
2016-02-06 14:33:15 +01:00
})
}
},
2016-02-06 14:33:15 +01:00
f = document.querySelectorAll("a.scroll");
(function b(c, d) {
var e = c.item(d);
e.addEventListener("click",
function(b) {
b.preventDefault();
h(e)
});
2016-02-06 14:33:15 +01:00
if (d) return b(c, d - 1)
})(f, f.length - 1)
});