optimization pass
[kengrimes.com/theme.git] / static / js / speedy.js
index 069b2d4..abd4d6f 100644 (file)
@@ -30,7 +30,7 @@ window.onload = () => {
   const navUp = () => nav.style.top = Math.min(parseInt(nav.style.top,10) + (oldScrollY - window.scrollY), 0) + 'px'
   const navDown = () => nav.style.top = Math.max(parseInt(nav.style.top,10) - (window.scrollY - oldScrollY), -nav.offsetHeight) + 'px'
   nav.style.top = 0 + 'px'
-  window.onscroll = () => {
+  const navUpdate = () => {
     if (window.matchMedia("(orientation: portrait)").matches) {
       if (window.scrollY < oldScrollY) /* up */ {
         if (upDelay-- <= 0)
@@ -46,7 +46,9 @@ window.onload = () => {
       }
       oldScrollY = window.scrollY
     }
+    window.requestAnimationFrame(navUpdate)
   }
+  navUpdate();
 }
   
 const resizeIFrame = (iframe) => {