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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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="page">
  <div class="page__wrapper">
    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>

    <div class="card">
      <p class="card__tags">CSS | ANIMATION | LERP</p>
      <div>
        <h3 class="card__title">Smooth Scroll Example With AnimationFrame & Linear Interpolation</h3>
        <p class="card__desc">24th December, 2021</p>
      </div>
    </div>
  </div>
</section>
              
            
!

CSS

              
                html {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

body {
  background: #fff;
  color: #a8a0a0;
  color: #333333;
  font-family: "system-ui";
}

.page {
  width: 100%;
  /*   height: calc(100vh - 1rem); */
  position: relative;
  /*   background-color: #333333; */
  background-color: #fff;
  position: abosolute;
/*   overflow: hidden; */
}

.page__wrapper {
  padding: 4rem 2rem;
}

.card {
  width: 600px;
  height: 450px;
  margin: auto;
  box-shadow: 0 0 25px 1px rgba(0, 0, 0, 0.1);
  padding: 4rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.card:not(:last-of-type) {
  margin-bottom: 5rem;
}

.card__tags {
  font-size: 0.8rem;
  font-weight: 500;
  margin: 0;
}

.card__title {
  font-size: 1.7rem;
  margin: 0;
  max-width: 70%;
  font-weight: 600;
  line-height: 1.3;
}

.card__desc {
  margin: 2rem 0 0;
  opacity: 0.7;
  font-size: 0.85rem;
}

              
            
!

JS

              
                // store components in variables
const page = document.querySelector(".page");
const wrapper = document.querySelector(".page__wrapper");

// ease value to be used in interpolation
const ease = 0.05; // 20%

// create an object to store scroll details
const scroll = {
  current: 0, // current scroll position
  target: 0, // target scroll position
  limit: 0 // limit of scroll
};

// function to update target scroll position
const updateTarget = (e) => {
  // set the target value to deltaY
  // which is distance covered by mouseWheel
  scroll.target += e.deltaY;
};

// create an event listener to listen for mouse-wheel
document.addEventListener("mousewheel", updateTarget);

// linear interpolation function
const lerp = (current, target) => {
  // get distance between current & target scroll points
  const distanceBetween = target - current;

  // get a percentage of that distance, in this case 20%
  const distanceToTravel = distanceBetween * ease;

  // add the % distance to the current scroll value
  return current + distanceToTravel;

  // shorthand for lerp is
  // current = current + ((target - current) * ease)
};

// clamping function to limit mousewheel values
const clamp = (min, max, value) => {
  const clamped = Math.min(Math.max(value, min), max);
  return clamped;
};

// main scroll function
const smoothScroll = () => {
  const maxScroll = wrapper.clientHeight - window.innerHeight;
  // clamp scroll target value
  scroll.target = clamp(0, maxScroll, scroll.target);

  const { current, target } = scroll;

  const transition = lerp(current, target);
  scroll.current = transition;

  // translate page wrapper based on lerped value
  wrapper.style.transform = `translateY(-${scroll.current}px)`;

  // use requestAnimationFrame with callback
  // to create an infinite loop of this function
  // that updates 60 times per second
  // or 30 times per second
  // depending on browser refresh rate
  window.requestAnimationFrame(smoothScroll);
};

// call smoothScroll to start loop
smoothScroll();

              
            
!
999px

Console