ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • How to make smooth scroll ?
    카테고리 없음 2021. 6. 17. 15:48

    Smooth scroll

    Add smooth scroll code to your hompage!

     

    Smooth Scroll Code

    const speed = 0.04;
    let height = 0;
    let offset = 0;
    
    const root = document.body;
    root.style.position = "absolute";
    root.style.width = "100%";
    
    const scrollWrap = root;
    if (scrollWrap) {
      height = scrollWrap.getBoundingClientRect().height - 1;
    }
    root.style.height = Math.floor(height) + "px";
    
    function smoothScroll() {
      offset += (window.pageYOffset - offset) * speed;
    
      var scroll =
        "translateY(-" + offset + "px) translateZ(0)";
      if (scrollWrap) {
        scrollWrap.style.transform = scroll;
      }
    
      requestAnimationFrame(smoothScroll);
    }
    
    smoothScroll();
    

    댓글

Designed by Tistory.