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

              
                <ul class="slider">
	<li class="slide">
		<img src="https://images.unsplash.com/photo-1542108226-9130e1e83cc4?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMDUwMDIwNA&ixlib=rb-1.2.1&q=80&w=1400" alt="">
		<h1>Slide 1</h1>
	</li>
	<li class="slide">
		<img src="https://images.unsplash.com/photo-1570458436416-b8fcccfe883f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMDUwMDIwNA&ixlib=rb-1.2.1&q=80&w=1400" alt="">
		<h1>Slide 2</h1>
	</li>
	<li class="slide">
		<img src="https://images.unsplash.com/photo-1611152615879-3ed367431f5f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMDUwMDIwNA&ixlib=rb-1.2.1&q=80&w=1400" alt="">
		<h1>Slide 3</h1>
	</li>
	<li class="slide">
		<img src="https://images.unsplash.com/photo-1450778869180-41d0601e046e?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMDUwMDIwNA&ixlib=rb-1.2.1&q=80&w=1400" alt="">
		<h1>Slide 4</h1>
	</li>
	<li class="slide">
		<img src="https://images.unsplash.com/photo-1514888286974-6c03e2ca1dba?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwxNDU4OXwwfDF8cmFuZG9tfHx8fHx8fHx8MTYzMDUwMDIwNA&ixlib=rb-1.2.1&q=80&w=1400" alt="">
		<h1>Slide 5</h1>
	</li>
	<!-- 	<div class="nav">
		<button class="prev">prev</button>
		<button class="next">next</button>
	</div>
	<ul class="dots"></ul> -->
	<!-- 	<div class="draggable"></div> -->

</ul>
              
            
!

CSS

              
                $brand-one: #85dbda;
$brand-two: #f53;
$brand-light: #fff;
$brand-dark: #0c162d;
$brand-grey: #637192;
$base-margin: 15px;
//------------------------------------------------------//
// Reset
//------------------------------------------------------//
* {
	box-sizing: border-box;
}
body {
	// overflow: hidden;
	margin: 0;
}
a {
	color: $brand-light;
}
h1,
h2,
h3,
h4,
h5,
h6 {
	font-family: sans-serif;
	margin-top: 0;
	margin-bottom: $base-margin;
}
// END Reset -------------------------------------//

//--------------------------------//
// Slider setup css (Do NOT edit)
//--------------------------------//
.slider {
	padding: 0;
	margin: 0;
	position: relative;
	width: 100%;
	height: 100vh;
	visibility: hidden;
	overflow: hidden;
	&.running {
		pointer-events: none;
	}
	// 🖼️ Slides
	.slide {
		user-select: none;
		list-style: none;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		img {
			object-fit: cover;
			width: 100%;
			height: 100%;
		}
	}
	// Navigation
	.nav {
		button {
			position: absolute;
			top: 50%;
			left: 30px;
			z-index: 1000;
			cursor: pointer;
			&:last-child {
				left: auto;
				right: 30px;
			}
		}
	}
	// ☝️ Touch
	.draggable {
		z-index: 100;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba($brand-two, 50%);
	}
	// 🟣 Dots
	.dots {
		display: flex;
		position: absolute;
		bottom: 30px;
		left: 50%;
		transform: translatex(-50%);
		z-index: 1000;
		padding: 0;
		margin: 0;
		li {
			margin: 5px;
			list-style: none;
			width: 10px;
			height: 10px;
			background-color: $brand-light;
			border-radius: 50%;
			cursor: pointer;
			opacity: 0.7;
			transition: opacity;
			transition-duration: 300ms;
			transition-timing-function: ease;
			&.active {
				opacity: 1;
				pointer-events: none;
			}
		}
	}
}
// END 🖼️ Slider setup css (Do NOT edit) --------------//

.slider {
	.slide {
		display: flex;
		justify-content: center;
		align-items: center;
		> * {
			position: absolute;
			z-index: 1000;
			color: $brand-light;
			font-size: 10vw;
		}
	}
	.dots {
		background-color: rgba($brand-dark, 10%);
		border-radius: 5px;
	}
}

              
            
!

JS

              
                console.clear(); // Just for codepen clear the console between refreshes
// gsap.registerPlugin(SplitText, Draggable);
document.querySelectorAll(".slider").forEach((container) => {
	// Setup variables
	const items = container.querySelectorAll(".slide"),
		itemsMax = items.length - 1;
	const next = container.querySelector(".next"),
		prev = container.querySelector(".prev"),
		dots = container.querySelector(".dots");
	let index = 0;
	const move = 100;
	const timer = 0;
	const duration = 5;
	let autoplay;
	//--------------------------------//
	// 💾 Inital setup
	//--------------------------------//
	function init() {
		// Create 🟣 Dots
		items.forEach((item, index) => {
			const dot = document.createElement("li");
			if (index === 0) dot.classList.add("active"); // Set the first dot to active
			// Allow clicking the dots
			dot.addEventListener("click", () => {
				slideLogic(false, index);
			});

			if (dots) dots.appendChild(dot);
		});
		// Animate the first element in
		gsap.set(items, { autoAlpha: 0 });
		gsap.set([".slider", items[index]], { autoAlpha: 1 });
		gsap.from(items[index], { autoAlpha: 0, y: move });
		autoplay = window.setTimeout(slideLogic, timer);
	}
	// Run inital setup
	init();
	// END 💾 Inital setup --------------//

	//--------------------------------//
	// ☝️ Touch
	//--------------------------------//
	if (window.Draggable) {
		Draggable.create(items, {
			type: "x", // Drag only on the X axis
			zIndexBoost: false,
			onDragStart: function () {
				window.clearTimeout(autoplay); // disable autoplay
				slideLogic(this.getDirection() === "right" ? true : false);
			}
		});
	}
	// END ☝️ Touch  --------------//

	//--------------------------------//
	// Set active 🟣 dot
	//--------------------------------//
	function dotActive(index) {
		const dotsAll = dots.querySelectorAll("li");
		dotsAll.forEach((dot) => {
			dot.classList.remove("active");
		});
		dotsAll[index].classList.add("active");
	}
	// END Set active 🟣 dot --------------//

	//--------------------------------//
	// 🖼️ Slide animation
	//--------------------------------//
	function slideAnimation(index, moveIn, outIn) {
		// Reset the properties you are animating below
		// Ohter wise they animate from that positon (probalby not visable)
		gsap.set(items, { yPercent: 0 });
		gsap.set(items[moveIn], { autoAlpha: 1 });

		// The animation
		const tl = gsap.timeline({
			defaults: {
				duration: duration,
				ease: "none"
			},
			onStart: animationStart,
			onComplete: animationDone
		});
		// Move out slide
		tl.to(items[index], { yPercent: outIn[0] });
		// move in slide
		tl.from(items[moveIn], { yPercent: outIn[1] }, "<");
		tl.set(items[index], { autoAlpha: 0 }); // Hide moved out slide
	}
	function animationStart() {
		container.classList.add("running");
	}
	function animationDone() {
		toggleButtons();
		autoplay = window.setTimeout(slideLogic, timer);
		container.classList.remove("running");
		gsap.set(items, { x: 0 });
	}
	// END 🖼️ Slide animation --------------//

	//--------------------------------//
	// Slider 🎛️ logic
	//--------------------------------//
	function slideLogic(prev, customMoveIn) {
		toggleButtons(); // Disable buttons
		window.clearTimeout(autoplay); // disable autoplay
		let outIn = [-move, move];
		if (prev) outIn.reverse();
		let moveIn;
		// Check if moveIn is passed with the function
		if (typeof customMoveIn === "undefined") {
			if (prev) {
				moveIn = index === 0 ? itemsMax : index - 1;
			} else {
				moveIn = index === itemsMax ? 0 : index + 1;
			}
		} else {
			moveIn = customMoveIn;
		}
		if (dots) dotActive(moveIn); // Set active dot
		slideAnimation(index, moveIn, outIn); // Animation function
		// Changing the next index
		if (typeof customMoveIn === "undefined") {
			if (prev) {
				index === 0 ? (index = itemsMax) : index--;
			} else {
				index === itemsMax ? (index = 0) : index++;
			}
		} else {
			index === itemsMax ? (index = 0) : (index = customMoveIn++);
		}
	}
	// END Slider 🎛️ logic --------------//

	//--------------------------------//
	// Button 🎛️ control
	//--------------------------------//
	function toggleButtons() {
		if (next) next.disabled = !next.disabled;
		if (prev) prev.disabled = !prev.disabled;
	}
	if (next) next.addEventListener("click", () => slideLogic());
	if (prev) prev.addEventListener("click", () => slideLogic(true));
	// END Button 🎛️ control --------------//
});

              
            
!
999px

Console