Do not smooth scrollIntoView

if user has it preferred

https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion
This commit is contained in:
Aditya Telange 2021-01-13 23:19:35 +05:30
parent dd83560010
commit b6a308d331
No known key found for this signature in database
GPG Key ID: 82E844EF3DA99E77

View File

@ -38,9 +38,13 @@
anchor.addEventListener("click", function (e) { anchor.addEventListener("click", function (e) {
e.preventDefault(); e.preventDefault();
var id = this.getAttribute("href").substr(1); var id = this.getAttribute("href").substr(1);
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({ if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
behavior: "smooth" document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({
}); behavior: "smooth"
});
} else {
document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView();
}
if (id === "top") { if (id === "top") {
history.replaceState(null, null, " "); history.replaceState(null, null, " ");
} else { } else {