-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy.js
31 lines (26 loc) · 962 Bytes
/
my.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// polyfill for `position: sticky;`
(function () {
var stickyElements = document.getElementsByClassName('sticky');
for (var i = stickyElements.length - 1; i >= 0; i--) {
Stickyfill.add(stickyElements[i]);
}
})();
// from http://stackoverflow.com/questions/14804941/how-to-add-smooth-scrolling-to-bootstraps-scroll-spy-function
(function () {
document.querySelectorAll(".nav a.nav-link[href^='#']")
.forEach(function (element) {
var target = element.href.replace(/.*#/, '#');
var navsize = document.querySelector('#navbar').offsetHeight;
element.addEventListener('click', function(e) {
e.preventDefault();
function updateWindowHash() {
window.location.hash = target;
}
$('html, body').animate(
{ scrollTop: document.querySelector(target).getBoundingClientRect().top + window.scrollY - navsize},
468,
updateWindowHash
);
});
});
})();