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

              
                <div class="c-exp-gallery__slider js-experience-slider">
  <div class="c-exp-gallery__inner js-experience-slider__inner">
    <div class="c-exp-gallery__content js-experience-slider__content">

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

      <div class="c-exp-gallery-slide js-experience-slide">
        <div class="c-exp-gallery-slide__proxy"></div>
        <figure class="c-exp-gallery-slide__img">
          <img src="https://images.unsplash.com/photo-1526973578717-38e3919604e8?ixlib=rb-0.3.5&q=85&fm=jpg&crop=entropy&cs=srgb&ixid=eyJhcHBfaWQiOjE0NTg5fQ&s=c737c70c1dc740c8285f0074eaaab520" alt="">
        </figure>
      </div>

    </div>
  </div>
  <div class="proxy"></div>
</div>
              
            
!

CSS

              
                @function size-calc($base) {
  $value: calc(#{$base} * (100vw / 1440));
  @return $value;
}

.c-exp-gallery__slider {
  position: relative;
}

.proxy {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
}

html,
body {
  height: 100%;
}

body {
  display: flex;
  align-items: center;
  overflow: hidden;
}

img {
  display: block;
  width: 100%;
  height: auto;
}

.c-exp-gallery {
  padding-bottom: size-calc(500);

  &__slider {
    width: 100vw;
  }

  &__inner {
    white-space: nowrap;
  }

  &-slide {
    display: inline-block;
    position: relative;
    padding: 0 size-calc(60);

    &__img {
      width: 50vw;
    }

    &__content {
      display: none;
      position: absolute;
      top: 100%;
      left: 0;
      right: 0;
      padding-top: size-calc(35);
    }
  }
}

              
            
!

JS

              
                // Original demo by @GreenSock - https://codepen.io/GreenSock/pen/JawEyN

gsap.config({ trialWarn: false });

gsap.registerPlugin(Draggable, InertiaPlugin);

const container = document.querySelector(".js-experience-slider");
const proxy = container.querySelector(".proxy");
const slider = document.querySelector(".js-experience-slider__inner");
const sliderContent = document.querySelector(".js-experience-slider__content");
const slides = [...container.querySelectorAll(".js-experience-slide")];

let sliderWidth = 0;
let pressedTop = false;
let offset = 0;

const setBounds = () => {
  sliderWidth = slides[0].offsetWidth * slides.length;

  gsap.to([slider, proxy], { width: sliderWidth, x: "+=0" });
};

setBounds();

const draggable = Draggable.create(proxy, {
  type: "x",
  bounds: container,
  throwProps: true,
  // edgeResistance: 0.75,
  edgeResistance: 1,
  dragResistance: 0.4,
  // ease: Power2.easeOut,
  onPress: function (e) {
    var bounds = this.target.getBoundingClientRect();
    pressedTop = e.clientY < bounds.y + bounds.height / 2;

    //keep track of how far apart the proxy is from the slider because when the user presses down, we want to IMMEDIATELY stop any motion, thus this offset value becomes baked in until release.
    // offset = this.x - slider._gsTransform.x;
    offset = this.x - gsap.getProperty(proxy, "x");

    gsap.killTweensOf(slider); //in case it's moving
    gsap.to(slider, { skewX: 0, duration: 0.2 });
  },
  onDrag: function () {
    gsap.to(slider, {
      duration: 0.8,
      x: this.x - offset,
      skewX: function (v) {
        var skew = InertiaPlugin.getVelocity(proxy, "x") / 200;
        // return pressedTop ? -skew : skew;
        return gsap.utils.clamp(-10, 10, skew);
      },
      overwrite: "auto",
      ease: "power2"
    });
  },
  onRelease: function () {
    // if the user just presses down and releases without really moving much at all, there's no need to do a throwProps tween.

    let velocity = InertiaPlugin.getVelocity(proxy, "x");
    if (this.tween && Math.abs(velocity) > 20) {
      gsap.to(slider, {
        overwrite: "auto",
        inertia: {
          x: {
            velocity: velocity,
            end: this.endX
          }
        }
      });
    }

    gsap.to(slider, { skewX: 0, duration: 0.5, overwrite: "auto" });
  }
});

              
            
!
999px

Console