From b5a267d84b3a71503fb407e2be39302f00a1e22d Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Pasquier Date: Wed, 14 Oct 2020 23:40:08 +0200 Subject: [PATCH] fix: firefox scroll --- src/scripts/firefox-scroll.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/scripts/firefox-scroll.js diff --git a/src/scripts/firefox-scroll.js b/src/scripts/firefox-scroll.js new file mode 100644 index 0000000..dd7862b --- /dev/null +++ b/src/scripts/firefox-scroll.js @@ -0,0 +1,23 @@ +document.addEventListener("DOMContentLoaded", () => { + window.scrollTo(0, 1); + let scrollTop = 1; + let fromTop = () => { + return window.pageYOffset || document.compatMode === "CSS1Compat" && document.documentElement.scrollTop || document.body.scrollTop || 0; + }; + + let isbody = setInterval(() => { + if (document.body) { + clearInterval(isbody); + scrollTop = fromTop(); + window.scrollTo(0, scrollTop === 1 ? 0 : 1); + } + }, 15); + + window.addEventListener("load", () => { + setTimeout(() => { + if (fromTop() < 20) { + window.scrollTo(0, scrollTop === 1 ? 0 : 1); + } + }, 0); + }); +}); \ No newline at end of file