2017-07-14 23:01:09 +02:00
|
|
|
(function () {
|
|
|
|
document.addEventListener("DOMContentLoaded", function(event) {
|
|
|
|
|
|
|
|
window.addEventListener('scroll', function (ev) {
|
|
|
|
var navbar = document.querySelector(".navbar");
|
|
|
|
var rect = navbar.getBoundingClientRect();
|
2017-09-28 21:26:11 +02:00
|
|
|
if (rect.top + window.scrollY > 50) {
|
2018-09-18 15:31:15 +02:00
|
|
|
navbar.classList.add("top-nav-collapse");
|
2017-07-14 23:01:09 +02:00
|
|
|
} else {
|
2018-09-18 15:31:15 +02:00
|
|
|
navbar.classList.remove("top-nav-collapse");
|
2017-07-14 23:01:09 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2017-09-28 21:26:11 +02:00
|
|
|
var getDocumentHeight = function () {
|
|
|
|
return Math.max(
|
|
|
|
document.body.scrollHeight, document.documentElement.scrollHeight,
|
|
|
|
document.body.offsetHeight, document.documentElement.offsetHeight,
|
|
|
|
document.body.clientHeight, document.documentElement.clientHeight
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2017-08-08 15:32:53 +02:00
|
|
|
Array.prototype.forEach.call(document.querySelectorAll('.page-scroll a'), function (el) {
|
2017-07-14 23:01:09 +02:00
|
|
|
el.addEventListener('click', function (ev) {
|
|
|
|
ev.preventDefault();
|
2018-09-18 15:31:15 +02:00
|
|
|
Array.prototype.forEach.call(document.querySelectorAll('.page-scroll'), function (child) {
|
|
|
|
child.classList.remove('active');
|
|
|
|
});
|
|
|
|
this.parentElement.classList.add('active');
|
|
|
|
|
|
|
|
var hash = this.getAttribute("href");
|
2017-09-28 21:26:11 +02:00
|
|
|
var endLocation = document.querySelector(hash).offsetTop;
|
|
|
|
var startLocation = window.pageYOffset;
|
|
|
|
var distance = endLocation - startLocation;
|
|
|
|
var start, percentage, position;
|
|
|
|
var timeLapsed = 0;
|
|
|
|
|
|
|
|
function scrollAnimation(timestamp) {
|
|
|
|
if (!start) { start = timestamp; }
|
|
|
|
timeLapsed += timestamp - start;
|
|
|
|
percentage = (timeLapsed / parseInt(500, 10));
|
|
|
|
percentage = (percentage > 1) ? 1 : percentage;
|
|
|
|
position = startLocation + (distance * percentage * percentage);
|
|
|
|
window.scrollTo(0, Math.floor(position));
|
|
|
|
|
|
|
|
var currentLocation = window.pageYOffset;
|
|
|
|
if (position == endLocation ||
|
|
|
|
currentLocation == endLocation ||
|
|
|
|
((startLocation < endLocation && window.innerHeight + currentLocation) >= getDocumentHeight())) {
|
|
|
|
window.location.hash = hash;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
window.requestAnimationFrame(scrollAnimation);
|
|
|
|
start = timestamp;
|
|
|
|
}
|
|
|
|
window.requestAnimationFrame(scrollAnimation);
|
2017-07-14 23:01:09 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
})();
|