Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <section class="smooth-scroll smoooth">
  <div class="smooth-scroll-inner smoooth-inner">
    <div class="intro">
      <h1 class="title is-size-1">Smoooth scroll</h1>
      <p class="subtitle">Using <span class="red">css transform</span> & <span class="red">css transition</span></p>
      <p>This is a super light script to achieve the trending smooth scrolling effect. <br> It's completely customizable, make something cool with it !</p>
      <p>You could start by making some curves here: <a target="_blank" href="https://cubic-bezier.com/">https://cubic-bezier.com/</a></p>
    </div>
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
    <img src="https://images.unsplash.com/photo-1524721696987-b9527df9e512?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=700&q=80" alt="">
  </div>
</section>
              
            
!

CSS

              
                //This is just for styling the demo
body {
  font-family: 'Avenir', Helvetica, sans-serif;
  color: #333;
  line-height: 1.5;
  text-align: center;
}

.title {
  font-size: 3rem;
  font-weight: bold;
  line-height: 1.2;
}

.subtitle {
  font-size: 1.5rem;
  margin-bottom: 1.5rem;
}

.intro {
  padding: 0 0 3rem 0;
}

.smooth-scroll {
  width: 100vw;
  height: 100vh;
  overflow: auto;
  background-color: whitsmoke;
}

.smooth-scroll-inner {
  padding: 3rem;
}

img {
  width: 100%;
  margin: 0 0 1.5rem 0;
  border-radius: 5px;
}

a {
  color: crimson;
}

.red {
  color: crimson;
}
              
            
!

JS

              
                function SmoothScroll(
  args = {
    outer: ".smoooth", //Your content wrapper
    inner: ".smoooth-inner", //Your content
    transition: "transform cubic-bezier(.05,.50,.45,1) 1s", //Easing while scrolling & timing. This is done in CSS.
    transitionEnd: "transform cubic-bezier(.15,.68,.44,1.26) 1s", //Easing when reaching the end of scrolling & timing. This is CSS.
    scrollRatio: 0.75, //Scroll speed, higher is faster
    touchRatio: 1, //Scroll speed on mobile devices
    skewRatio: 0.02, //Skew effect on content, set it to zero to disable it
    touchSkewRatio: 0.01, //Skew effect on mobile because it has to be calculated differently
    scrollProgress: true,
    scrollProgressColor: "#333",
    scrollProgressWidth: "4px"
  }
) {
  let head = document.querySelector("head");

  let styles = document.createElement("style");
  styles.innerHTML = `
  html, body { overflow: hidden; width: 100vw; height: 100vh; } ${args.outer} { overflow: hidden; }
  .smoooth-scroll-progress { position: fixed; right: 0; top: 0; background: ${args.scrollProgressColor}; width: ${args.scrollProgressWidth}; z-index: 999999; }
  `;
  head.appendChild(styles);

  let body,
    scrollProgress,
    inner,
    outer,
    position,
    innerY,
    windowY,
    touchStartPos,
    touchStart,
    touchMove,
    touchDelta,
    skew;

  inner = document.querySelector(args.inner);
  outer = document.querySelector(args.outer);
  position = 0;
  skew = 0;

  window.addEventListener("resize", function () {
    innerY = inner.clientHeight;
    windowY = window.innerHeight;
  });

  innerY = inner.clientHeight;
  windowY = window.innerHeight;

  if (args.scrollProgress) {
    body = document.querySelector("body");
    scrollProgress = document.createElement("div");
    scrollProgress.classList.add("smoooth-scroll-progress");
    body.appendChild(scrollProgress);
  }

  function translateContent() {
    innerY = inner.clientHeight;
    windowY = window.innerHeight;
    if (position <= -(innerY - windowY)) {
      position = -(innerY - windowY);
      inner.style.transition = args.transitionEnd;
      inner.style.transform = `translate3d(0,${position}px,0)`;
    } else if (position >= 0) {
      position = 0;
      inner.style.transition = args.transitionEnd;
      inner.style.transform = `translate3d(0,${position}px,0)`;
    } else {
      inner.style.transition = args.transition;
      inner.style.transform = `translate3d(0,${position}px,0)skewY(${skew}deg)`;
    }
    if (args.scrollProgress) {
      scrollProgress.style.height = `${
        (-position / (innerY - windowY)) * windowY
      }px`;
    }
    requestAnimationFrame(translateContent);
  }

  function onScroll(e) {
    position -= e.deltaY * args.scrollRatio;
    skew = e.deltaY * args.skewRatio;
  }

  window.addEventListener(
    "wheel",
    function (e) {
      onScroll(e);
    },
    { passive: true }
  );

  window.addEventListener(
    "touchstart",
    function (e) {
      touchStart = e.touches[0].clientY;
      touchStartPos = position;
    },
    { passive: true }
  );

  window.addEventListener(
    "touchmove",
    function (e) {
      touchMove = e.touches[0].clientY;
      touchDelta = touchStart - touchMove;
      position = touchStartPos - touchDelta * args.touchRatio;
      skew = touchDelta * args.touchSkewRatio;
    },
    { passive: true }
  );

  window.addEventListener(
    "touchend",
    function (e) {
      touchStartPos = position;
      touchMove = 0;
      skew = 0;
    },
    { passive: true }
  );

  translateContent();
}

document.addEventListener("DOMContentLoaded", SmoothScroll());
              
            
!
999px

Console