ehylam
5/7/2020 - 10:38 AM

JS Smooth scrolling

const body = document.body,
             scrollWrap = document.getElementsByClassName("wrapper_class")[0],
             height = scrollWrap.getBoundingClientRect().height -1,
             speed = 0.04;
             
var offset = 0;

body.style.height = Math.floor(height) + "px";

function smoothScroll() {
  offset += (window.pageYOffset - offset) * speed;
  var scroll = "translateY(-" + offset + "px) translateZ(0)";
  scrollWrap.style.transform = scroll;
}