From b6a308d331d7ef2f59599203eb3b59890baef8ac Mon Sep 17 00:00:00 2001 From: Aditya Telange <21258296+adityatelange@users.noreply.github.com> Date: Wed, 13 Jan 2021 23:19:35 +0530 Subject: [PATCH] Do not smooth scrollIntoView if user has it preferred https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion --- layouts/partials/footer.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 4623b3ff..f5ca45d6 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -38,9 +38,13 @@ anchor.addEventListener("click", function (e) { e.preventDefault(); var id = this.getAttribute("href").substr(1); - document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({ - behavior: "smooth" - }); + if (!window.matchMedia('(prefers-reduced-motion: reduce)').matches) { + document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView({ + behavior: "smooth" + }); + } else { + document.querySelector(`[id='${decodeURIComponent(id)}']`).scrollIntoView(); + } if (id === "top") { history.replaceState(null, null, " "); } else {