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

59 lines
2.0 KiB
JavaScript

//
// 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);
d.get("elapsed") < d.get("duration") ? requestAnimationFrame(l) : (null, null, b, e.scrollTop = c.get("start") + c.get("delta"))
})
}
},
f = document.querySelectorAll("a.scroll");
(function b(c, d) {
var e = c.item(d);
e.addEventListener("click",
function(b) {
b.preventDefault();
h(e)
});
if (d) return b(c, d - 1)
})(f, f.length - 1)
});