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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                <main>
    <h1>Custom scroll</h1>
    <div class="scroll-wrapper">
        <div class="scroll-filler"></div>
        <div class="scroll">
            <div class="scroll-inner">
                <a href="#" class="scroll-item">
                    <h2>I made a slider</h2>
                    <span class="scroll-item-date">5 Jun 2020</span>
                </a>
                <a href="#" class="scroll-item red">
                    <h2>I don't know how to make a slider</h2>
                    <span class="scroll-item-date">4 Jun 2020</span>
                </a>
                <a href="#" class="scroll-item">
                    <h2>I want to make a slider</h2>
                    <span class="scroll-item-date">3 Jun 2020</span>
                </a>
                <a href="#" class="scroll-item bees">
                    <h2>bees</h2>
                    <span class="scroll-item-date">bees</span>
                </a>
                <a href="#" class="scroll-item red">
                    <h2>---------</h2>
                    <span class="scroll-item-date">---------</span>
                </a>
                <a href="#" class="scroll-item">
                    <h2>ь</h2>
                    <span class="scroll-item-date">ъ</span>
                </a>
                <a href="#" class="scroll-item blue"></a>
                <div class="scroll-item ghost">
                    <h2>No more items</h2>
                    <span class="scroll-item-date">For real</span>
                </div>
            </div>
        </div>
    </div>
    <div class="scroll-position-wrapper">
        <button class="scroll-btn prev" onclick="prevBtn()" disabled></button>
        <div class="scroll-position">
            <div class="scroll-position-inner"></div>
        </div>
        <button class="scroll-btn next" onclick="nextBtn()"></button>
    </div>

    <div class="info">
        <p>This is a slider. Try scrolling!</p>
        <p><a target="_blank" href="https://tympanus.net/codrops/2019/07/10/how-to-add-smooth-scrolling-with-inner-image-animations-to-a-web-page/">Inspired by this demo.</a></p>
      <p class="sub">Using a mouse? Hold <b>Shift</b> and scroll.
    </div>

    <footer>
        <a href="https://codepen.io/theseventh" target="_blank">Codepen</a>
        <a href="https://twitter.com/the_seventh_kek" target="_blank">Twitter</a>
        <a href="https://t.me/the_seventh" target="_blank">Telegram</a>
    </footer>
</main>
              
            
!

CSS

              
                html, body {
  padding: 20px;
  margin: 0;
  background-color: #dfe9ef;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100%;
  font-family: 'Manrope', sans-serif;
  color: #31393d;
}

* {
  box-sizing: border-box;
  outline: none;
  -webkit-tap-highlight-color: rgba(0,0,0,0);
}

main {
  width: 300px;
  height: 550px;
  background-color: white;
  border-radius: 16px;
  overflow: hidden;
  padding: 30px 20px 20px;
  box-shadow: 0 6px 20px 0 rgba(202, 208, 216, 0.15);
  display: flex;
  flex-direction: column;

  h1 {
    font-size: 1.4em;
    margin-top: 0;
    margin-bottom: 10px;
    font-weight: 800;
  }
}

::-webkit-scrollbar {
  display: none;
  width: 0;
  background: transparent;
  height: 0;
  -webkit-appearance: none;
}

.scroll {
  &-wrapper {
    height: fit-content;
    margin-left: -20px;
    margin-right: -20px;
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: none;
  }
  
  // this is the most problematic part that actually breaks the slider in Safari. I think the problem has something to do with 'position: sticky', but it doesn't seem fixable for now.
  padding: 20px 20px 40px;
  white-space: nowrap;
  position: sticky;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;

  &-filler {
    width: 100%;
    height: 100%;
    position: absolute;
  }

  &-inner {
    width: fit-content;
    display: flex;
    align-items: stretch;
  }

  &-item {
    width: 160px;
    border-radius: 16px;
    background-image: linear-gradient(130deg, #9457e2, #5029bb);
    transform: perspective(400px);
    box-shadow: 0 8px 20px 0 rgba(108, 79, 197, 0.44);
    padding: 20px 30px;
    vertical-align: top;
    color: white;
    text-decoration: none;
    white-space: normal;
    display: flex;
    flex-direction: column;

    &.red {
      background-image: linear-gradient(130deg, #ff8063, #e34040);
      box-shadow: 0 8px 20px 0 rgba(213, 65, 51, 0.45);
    }

    &.bees {
      background-image: linear-gradient(130deg, #ffe561, #ffd24c);
      box-shadow: 0 8px 20px 0 rgba(227, 169, 55, 0.45);
      color: #333;
    }

    &.blue {
      background-image: linear-gradient(130deg, #1cffb7, #0075ff);
      box-shadow: 0 8px 20px 0 rgba(107, 187, 255, 0.45);
    }

    &.ghost {
      background-image: none;
      box-shadow: none;
      border: 1px dashed #eaeaea;
      color: #bdbdbd;
      cursor: default;
    }

    &:not(:last-child) {
      margin-right: 0;
    }

    h2 {
      font-size: 1.15em;
      font-weight: 600;
      line-height: 1.5;
      margin: 0 0 30px;
    }

    .scroll-item-date {
      font-size: .8em;
      letter-spacing: .02em;
      opacity: .8;
      display: block;
      margin-top: auto;
    }
  }

  &-position {
    &-wrapper {
      width: 100%;
      margin-top: -10px;
      display: flex;
      align-items: center;
    }

    height: 1px;
    background-color: #f1f1f1;
    flex: 1;
    margin: 0 5px;

    &-inner {
      height: 1px;
      background-color: #d0d0d0;
    }
  }

  &-btn {
    display: block;
    appearance: none;
    border: none;
    background: none;
    width: 26px;
    height: 26px;
    background-color: white;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24' fill='none' stroke='%23aaa' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'%3E%3C/polyline%3E%3C/svg%3E");
    background-position: center;
    background-size: 20px;
    z-index: 9;
    cursor: pointer;
    opacity: .6;
    color: rgba(179, 179, 179, 0.7);
    transition-duration: .3s;

    &:hover {
      opacity: 1;
    }

    &.prev {
      transform: scaleX(-1);
    }

    &[disabled] {
      opacity: 0;
      pointer-events: none;
    }
  }
}

.info {
  padding: 10px;
  text-align: center;
  border-radius: 4px;
  box-shadow: 0 0 0 1px #ececec;
  margin-top: 30px;
  position: relative;

  p {
    color: #898e90;
    font-size: 0.9em;
    margin: 5px 10px;
    
    &.sub {
      font-size: .7em;
      margin-top: 7px;
      opacity: .5;
      line-height: 1;
    }

    a {
      color: #6c5dff;
      text-decoration: none;
      opacity: .8;

      &:hover {
        opacity: 1;
      }
    }
  }
}

footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  margin-top: auto;

  a {
    display: block;
    color: #d7d7d7;
    font-size: .8em;
    text-decoration: none;
    border-bottom: 1px solid transparent;
    transition-duration: .2s;
    padding-bottom: 1px;
    line-height: 1.3;

    &:hover {
      color: #9e94ff;
      border-color: currentColor;
    }
  }
}
              
            
!

JS

              
                const wrapper = document.querySelector('.scroll-wrapper');
const el = document.querySelector('.scroll');
const filler = document.querySelector('.scroll-filler');
const position = document.querySelector('.scroll-position-inner');
const inner = document.querySelector('.scroll-inner');
const btns = {prev: document.querySelector('.scroll-btn.prev'), next: document.querySelector('.scroll-btn.next')};

const lerp = (a, b, n) => {
  return (1 - n) * a + n * b
}

const padding = 20;

let scrollNow = 0;

filler.style.width = inner.offsetWidth + padding*2 + 'px';
position.style.width = wrapper.offsetWidth / (inner.offsetWidth + padding*2) * 100 + '%';

const offset = 150;
const angle = 25;
const z = 15;

function render() {
  let now = lerp(scrollNow, wrapper.scrollLeft, .15);
  gsap.set(el, {x: -now});
  gsap.set(position, {x: now / wrapper.offsetWidth * 100 + '%'});

  document.querySelectorAll('.scroll-item').forEach(item => {
    let elPos = item.offsetLeft + item.offsetWidth / 2 - scrollNow;

    if (elPos > wrapper.offsetWidth - offset) {
      let q = (wrapper.offsetWidth - elPos) / offset;
      gsap.set(item, {rotateY: -(angle - q * angle), z: z - z * q})
    } else if (elPos < offset) {
      let q = elPos / offset;
      gsap.set(item, {rotateY: angle - q * angle, z: z - z * q})
    } else {
      gsap.set(item, {rotateY: 0, z: 0});
    }
  });

  scrollNow = now;

  if (wrapper.scrollLeft === 0) btns.prev.disabled = true
  else if (inner.offsetWidth - wrapper.scrollLeft === wrapper.offsetWidth - padding*2) btns.next.disabled = true
  else {btns.prev.disabled = false; btns.next.disabled = false;}
  requestAnimationFrame(render);
}

render();

function nextBtn() {
  wrapper.scrollLeft += document.querySelector('.scroll-item').offsetWidth*2 - 20;
}
function prevBtn() {
  wrapper.scrollLeft -= document.querySelector('.scroll-item').offsetWidth*2 - 20;
}
              
            
!
999px

Console