Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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="container">
  <div class="carousel">
    <div class="flair"></div>
    <div class="flair flair--2"></div>
    <div class="flair flair--3"></div>
    <div class="flair flair--4"></div>
    <div class="flair flair--23"></div>
    <div class="flair flair--6"></div>
  </div>
  <h4>Spin the shapes and let go. Notice inertia is preserved.</h4>
</div>
              
            
!

CSS

              
                html, body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.container {
  position: relative;
  width: 90vw;
  height: 90vh;
  max-width: 90vh;
  max-height: 90vw;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  overflow: hidden;

}
.carousel .flair {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 38%;
  height: 38%;
}
.carousel {
  position: relative;
  width: 100%;
  height: 80%;
  perspective: 800px;
  transform-style: preserve-3d;
  transform: rotateX(-20deg);
}
h4 {
  color: var(--mid);
  position: relative;
  width: 100%;
  left: 0;
  right: 0;
  bottom: 1rem;
  text-align: center;
  pointer-events: none;
  padding: 0px 8px;
  box-sizing: border-box;
}

svg {
  overflow: visible;
  height: 100%;
  width: 100%;
}

path {
  stroke-width: 2;
  stroke: var(--light);
}
#hippo, #elephant, #star{
  visibility:hidden;
}



@media (max-width: 350px) or (max-height: 350px) {
  .container h4 {
    display: none;
  }
}
              
            
!

JS

              
                gsap.registerPlugin(Draggable, InertiaPlugin);

var shapes = gsap.utils.toArray(".flair"),
    dragDistancePerRotation = 2000,
    proxy = document.createElement("div"), // just a dummy element that'll get dragged, but we don't care about it.
    progressWrap = gsap.utils.wrap(0, 1),
    spin = gsap.fromTo(shapes, {
      rotationY: i => i * 360 / shapes.length
    }, {
      rotationY: "-=360",
      duration: 20,
      ease: "none",
      repeat: -1,
    }),
    startProgress;

Draggable.create(proxy, {
  trigger: ".carousel", // activate the dragging when the user presses on the .demoWrapper
  type: "x", // we only care about movement on the x-axis.
  inertia: true,
  allowNativeTouchScrolling: true,
  onPress() {
    gsap.killTweensOf(spin); // if it's in the middle of animating the spin back to timeScale: 1, kill that.
    spin.timeScale(0); // stop the spin.
    startProgress = spin.progress(); // remember the current progress value because we'll make the drag relative to that.
  },
  onDrag: updateRotation,
  onThrowUpdate: updateRotation,
  onRelease() {
    if (!this.tween || !this.tween.isActive()) { // if the user clicked and released (no inertia flick), resume the spin
      gsap.to(spin, {timeScale: 1, duration: 1});
    }
  },
  onThrowComplete() { // resume the spin after the inertia tween finishes
    gsap.to(spin, {timeScale: 1, duration: 1});
  }
});

function updateRotation() {
  let p = startProgress + (this.startX - this.x) / dragDistancePerRotation;
  spin.progress(progressWrap(p));
}

function adjustRadius() {
  let radius = Math.min(window.innerWidth, window.innerHeight) * 0.45;
  gsap.set(shapes, {
    xPercent: -50,
    yPercent: -50,
    x: 0,
    y: 0,
    transformOrigin: "50% 50% " + -radius + "px"
  });
}
adjustRadius();
window.addEventListener("resize", adjustRadius);
              
            
!
999px

Console