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 id="smooth-content">
	<div class="section-container" id="panelcontainer">
		<section class="panel" id="panel_0"></section>
		<section class="panel" id="panel_1"></section>
		<section class="panel" id="panel_2"></section>
		<section class="panel" id="panel_3"></section>
	</div>
</div>
              
            
!

CSS

              
                @charset "UTF-8";

html,
body {
	padding: 0;
	margin: 0;
}

body {
	width: 100%;
	height: 100vh;
	position: absolute;
	overflow-x: hidden;
	top: 0;
	left: 0;
	padding: 0;
	margin: 0;
}

#panelcontainer {
	height: 100%;
	position: relative;
}

.panel {
	position: absolute;
	width: 100%;
	height: 100vh;
	background-repeat: no-repeat;
	background-size: cover;
	background-position: center center;
	will-change: opacity, transform;
}

#panel_0 {
	background-image: url("https://via.placeholder.com/800x800/ffffff?text=one");
	background-color: olive;
}

#panel_1 {
	background-image: url("https://via.placeholder.com/800x800/000000?text=two");
	background-color: teal;
}

#panel_2 {
	background-image: url("https://via.placeholder.com/800x800/ffffff?text=three");
	background-color: steelBlue;
}

#panel_3 {
	background-image: url("https://via.placeholder.com/800x800/000000?text=four");
	background-color: sienna;
}

              
            
!

JS

              
                // simplified down to remove the classes and function calls
// just show the bare necessities as simply as possible
gsap.registerPlugin(ScrollTrigger, ScrollSmoother);

// create the scrollSmoother before your scrollTriggers
ScrollSmoother.create({
	smooth: 1,
	smoothTouch: 0.1
});

let panels = gsap.utils.toArray(".panel");
let container = document.querySelector("#panelcontainer");
let winW = Math.min(window.innerWidth, document.documentElement.clientWidth);
let winH = Math.max(window.innerHeight, document.documentElement.clientHeight);

panels.forEach((panel, i) => {
	// simplified setupsizes
	gsap.set(panel, {
		height: Math.floor(winH) + "px", // make it a little taller than the screen to allow for bars
		width: Math.floor(winW) + "px"
	});

	if (i === 0) return;
	gsap.set(panel, { yPercent: 4, autoAlpha: 0, scale: 1.08 });
});

let tl = gsap.timeline();

tl.addLabel("panel0");

panels.forEach((panel, i) => {
	tl.to(panel, { yPercent: 0, autoAlpha: 1, scale: 1 });
	tl.addLabel("panel" + i);
});

gsap.set("#panelcontainer", {
	height: (panels.length * Math.floor(winH)).toString() + "px",
	width: winW + "px"
});

// typo
// console.log(panels.lenght, "🙈");

ScrollTrigger.create({
	trigger: container,
	start: "top top",
	end: `${(panels.length * Math.floor(winH)).toString()}px bottom`, // there was a typo here (panels.lenght) - returning undefined
	scrub: true,
	pin: true,
	pinSpacing: false,
	markers: true,
	// invalidateOnRefresh: true,
	snap: {
		snapTo: "labelsDirectional",
		duration: { min: 0.1, max: 0.3 },
		directional: true,
		inertia: false
	},
	animation: tl,
	id: "panelScrollTrigger",
	onLeave: (self) => {
		console.log("🧨 leave");
	},
	onToggle: (self) => {
		console.log("snap toggle");
	},
	onSnapComplete: (self) => {
		console.log("Snap complete");
	}
});

              
            
!
999px

Console