[FIX] Seite im IE falsch dargestellt

This commit is contained in:
Christian Seyfferth 2020-04-22 22:04:52 +02:00
parent a5ee3ace74
commit 4314fd4214

View File

@ -10,31 +10,80 @@ document.addEventListener('DOMContentLoaded', function () {
});
var mailcypts = document.querySelectorAll(".cryptmail");
mailcypts.forEach(element => {
element.onclick = function () {
for (var i = 0; i < mailcypts.length; i++) {
mailcypts[i].onclick = function () {
window.location.href = 'mailto:' + this.dataset.name + '@' + this.dataset.domain + '.' + this.dataset.tld;
return false;
}
});
}
var hashAnchors = document.querySelectorAll("a[href^='#']");
hashAnchors.forEach(element => {
element.onclick = function () {
for (var i = 0; i < hashAnchors.length; i++) {
hashAnchors[i].onclick = function () {
var target = this.getAttribute("href");
scrollToElement(target);
return false;
}
});
}
});
function scrollToElement(name) {
var elementToScrollTo = document.querySelector(name);
var top = elementToScrollTo.getBoundingClientRect().top + window.pageYOffset - 48;
const navbarScrollOffset = -48;
// native smooth scrolling for Chrome, Firefox & Opera
// @see: https://caniuse.com/#feat=css-scroll-behavior
const nativeSmoothScrollTo = function (elem) {
window.scroll({
behavior: 'smooth',
left: 0,
top: elem.getBoundingClientRect().top + window.pageYOffset + navbarScrollOffset
});
};
window.scrollTo({
top: top,
behavior: "smooth"
})
}
// polyfilled smooth scrolling for IE, Edge & Safari
const smoothScrollTo = function (to, duration) {
const element = document.scrollingElement || document.documentElement,
start = element.scrollTop,
change = to - start,
startDate = +new Date();
// t = current time
// b = start value
// c = change in value
// d = duration
const easeInOutQuad = function (t, b, c, d) {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
};
const animateScroll = function () {
const currentDate = +new Date();
const currentTime = currentDate - startDate;
element.scrollTop = parseInt(easeInOutQuad(currentTime, start, change, duration));
if (currentTime < duration) {
requestAnimationFrame(animateScroll);
} else {
element.scrollTop = to;
}
};
animateScroll();
};
// detect support for the behavior property in ScrollOptions
const supportsNativeSmoothScroll = 'scrollBehavior' in document.documentElement.style;
// smooth scrolling stub
const scrollToElement = function (elemSelector) {
if (!elemSelector) {
return;
}
const elem = document.querySelector(elemSelector);
if (elem) {
if (supportsNativeSmoothScroll) {
nativeSmoothScrollTo(elem);
} else {
smoothScrollTo(elem.offsetTop + navbarScrollOffset, 600);
}
}
};