forked from nova-script/smooth-scrolling.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
smooth-scrolling.min.js
1 lines (1 loc) · 1.36 KB
/
smooth-scrolling.min.js
1
class SmoothScroll{constructor(){const e=1e3,t="cubic-bezier(0.23, 1, 0.32, 1)";this.necessaryElements={container:document.querySelector(".ss--container"),containerBody:document.querySelector(".ss--container__body"),hitbox:document.querySelector(".ss--container--hitbox")},this.parameters={containerHeight:this.necessaryElements.containerBody.offsetHeight,duration:e,timingFunction:t},document.addEventListener("DOMContentLoaded",()=>{this.initStyle(),this.initListeners()})}initStyle(){this.necessaryElements.container.style.overflow="hidden",this.necessaryElements.container.style.position="fixed",this.necessaryElements.container.style.height="100vh",this.necessaryElements.hitbox.style.height=this.parameters.containerHeight+"px",this.necessaryElements.containerBody.style.transform="translateY("+window.scrollY+"px)",this.necessaryElements.containerBody.style.transition="transform "+this.parameters.duration+"ms "+this.parameters.timingFunction}initListeners(){window.addEventListener("scroll",()=>{this.handleScroll()}),window.addEventListener("resize",()=>{this.handleResize()})}handleScroll(e){this.necessaryElements.containerBody.style.transform="translateY("+-1*window.scrollY+"px)"}handleResize(){this.parameters.containerHeight=this.necessaryElements.containerBody.offsetHeight,this.necessaryElements.hitbox.style.height=this.parameters.containerHeight+"px"}}new SmoothScroll;