default scroll behavior

This commit is contained in:
2022-06-15 16:50:55 +03:00
parent d68224091d
commit 6724bbf621

View File

@@ -2,11 +2,13 @@ let current = -1;
let currentScrolled = -1;
let scrollTimer = null;
let scrollEventTimer = null;
let defaultScroll = "smooth";
function r(f) {
/in/.test(document.readyState) ? setTimeout('r(' + f + ')', 9) : f()
}
r(function() {
defaultScroll = typeof document.body.dataset.scroll === "string" ? document.body.dataset.scroll : "smooth";
create_nav();
document.onkeydown = keyboard_entry;
});
@@ -37,7 +39,7 @@ function create_button(direction, to, next) {
button.classList.add("navigation_button");
button.onclick = function() {
to.parentElement.scrollIntoView({
behavior: "smooth"
behavior: defaultScroll
});
current = next;
};
@@ -132,7 +134,7 @@ function keyboard_entry(ev) {
return
}
if (current == -1) {
window.scrollTo({ top: 0, behavior: 'smooth' });
window.scrollTo({ top: 0, behavior: defaultScroll });
return
}
current = Math.max(0, current);
@@ -145,7 +147,7 @@ function keyboard_entry(ev) {
clearTimeout(scrollTimer);
} else {
posts[current].parentElement.scrollIntoView({
behavior: "smooth"
behavior: defaultScroll
});
}
scrollTimer = setTimeout(function() {