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

              
                <div id="card-container">
			<div id="card1" class="card"></div>
			<div id="card2" class="card"></div>
			<div id="card3" class="card"></div>
      <div id="card4" class="card"></div>
		</div>
		<div id="arrow-right" class="arrow" style="z-index:4;">
			<svg viewBox="0 0 5.99 9.86"><polyline points="5.24 9.11 1.06 4.93 5.24 0.75" fill="none" stroke="#fff" stroke-linecap="round" stroke-miterlimit="10" stroke-width="1.5"></polyline></svg>
		</div>
		<div id="arrow-left" class="arrow" style="z-index:4;">
			<svg viewBox="0 0 5.99 9.86"><polyline points="5.24 9.11 1.06 4.93 5.24 0.75" fill="none" stroke="#fff" stroke-linecap="round" stroke-miterlimit="10" stroke-width="1.5"></polyline></svg>
		</div>
              
            
!

CSS

              
                div, img, svg{
	position: absolute;
}
#card-container{
	width: 300px;
	height: 250px;
	display: flex;
	align-items: center;
	justify-content: center;
}
#card-container .card{
	width: 280px;
	height: 200px;
	border-radius: 5px;
	box-shadow: 3px 2px 10px -5px rgba(0,0,0,0.51);
	-webkit-box-shadow: 3px 2px 10px -5px rgba(0,0,0,0.51);
	-moz-box-shadow: 3px 2px 10px -5px rgba(0,0,0,0.51);
	background-color:#fff;
}

.arrow svg{
	width: 10px;
	height: 20px;
}
#arrow-right{
	top: 210px;
	left: 45px;
	width: 30px;
	height: 30px;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: center;
	-webkit-transform: rotate(-180deg);
	-moz-transform: rotate(-180deg);
	-ms-transform: rotate(-180deg);
	-o-transform: rotate(-180deg);
	transform: rotate(-180deg);
}

#arrow-left{
	top: 210px;
	left: 10px;
	width: 30px;
	height: 30px;
	background-color: rgba(0, 0, 0, 0.5);
	display: flex;
	justify-content: center;
	align-items: center;
}

#card1{
	background-color:red !important;
}
#card2{
	background-color:green !important;
}
#card3{
	background-color:blue !important;
}
#card4{
	background-color:yellow !important;
}
              
            
!

JS

              
                let cards = gsap.utils.toArray(".card"),
    // build a timeline with a cardAnimation that starts every 0.5 seconds
    loop = buildSeamlessLoop(cards, 0.5, cardAnimation),
    time = 0.2; 

// start at 0.2 seconds into the timeline because that's when the item is in the correct position (we fade for the final 0.2 seconds of the cardAnimation)
loop.time(time);

// this function gets called by the buildSeamlessLoop() for each card. We just need to return the animation that we'd like, and it'll stagger them out on a timeline for us. 
function cardAnimation(card) {
  let start = {y: -40, scale: 0.9, zIndex: 0, opacity: 1};
  return gsap.timeline()
    .fromTo(card, start, {y: 0, scale: 1, opacity: 1, zIndex: 100, ease: "none", duration: 2, immediateRender: false})
    .fromTo(card, {opacity: 1}, {opacity: 0, duration: 0.2, immediateRender: false})
    .set(card, start);
}

document.getElementById('arrow-right').addEventListener("click", () => movePlayhead(0.5));
document.getElementById('arrow-left').addEventListener("click", () => movePlayhead(-0.5));

// animates the playhead on the loop by a certain amount (tweens it over the course of 0.5 seconds);
function movePlayhead(amount) {
  time += amount;
  if (time < 0) { // can't go negative, so just jump ahead 100 iterations and resume.
    loop.totalTime(loop.totalTime() + loop.duration() * 100);
    time += loop.duration() * 100;
  }
  gsap.to(loop, {totalTime: time, duration: 0.5, overwrite: true});
}


// helper function that loops through the items 3 times, calling the animateFunc() for each item, then creates a tween of the playhead that focuses only on the 2nd iteration so that it's seamless (we need to pad the start and end with one iteration so that things aren't just coming in from a blank screen at the beginning)
function buildSeamlessLoop(items, spacing, animateFunc) {
	let rawSequence = gsap.timeline({paused: true}), // this is where all the "real" animations live
		seamlessLoop = gsap.timeline({ // this merely scrubs the playhead of the rawSequence so that it appears to seamlessly loop
			paused: true,
			repeat: -1, // to accommodate infinite scrolling/looping
			onRepeat() { // works around a super rare edge case bug that's fixed GSAP 3.6.1
				this._time === this._dur && (this._tTime += this._dur - 0.01);
			},
      onReverseComplete() {
        this.totalTime(this.rawTime() + this.duration() * 100); // seamless looping backwards
      }
		}),
		cycleDuration = spacing * items.length,
		dur; // the duration of just one animateFunc() (we'll populate it in the .forEach() below...

	// loop through 3 times so we can have an extra cycle at the start and end - we'll scrub the playhead only on the 2nd cycle
	items.concat(items).concat(items).forEach((item, i) => {
		let anim = animateFunc(items[i % items.length]);
		rawSequence.add(anim, i * spacing);
		dur || (dur = anim.duration());
	});

	// animate the playhead linearly from the start of the 2nd cycle to its end (so we'll have one "extra" cycle at the beginning and end)
	seamlessLoop.fromTo(rawSequence, {
		time: cycleDuration + dur / 2
	}, {
		time: "+=" + cycleDuration,
		duration: cycleDuration,
		ease: "none"
	});
	return seamlessLoop;
}
              
            
!
999px

Console