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

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="wrapper">
	<div id="content">
		
		<div class="sections">
		
			<section class="section-1">
				
				<div class="c-title">
					
					<div class="info">
						
						<div class="sub-title sub-title-1 font-book font-slant">
							<em>GSAP</em>
						</div>
						
						<div class="title title-1 font-bold font-slant">
							<div class="title-text">Drag Demo</div>
						</div>
						
						<div class="sub-title sub-title-2 font-book font-slant">
							<em>v3.10</em>
						</div>
						
						<div class="title title-2 font-medium font-slant">
							<div class="title-text"><span class="font-book">with</span> ScrollSmoother</div>
						</div>
						
					</div>
						
					<div class="indicator">
						<div class="pointer">
							☟
						</div>
					</div>
					
					<div class="credit font-medium">
						By: <a href="https://vanholtz.co" target="_blank" rel="noopener" data-ignore>Eric Van Holtz</a>
					</div>
					
				</div>
				
			</section>
			
			<section class="section-2 font-book" data-speed="0.75">
				
				<div class="info">
					
					<div class="text">For more information visit:</div>
					
					<a class="font-medium" href="https://greensock.com/docs/v3/Plugins/ScrollSmoother" target="_blank" rel="noopener" data-ignore>
						The Greensock Docs
					</a>
					
				</div>
				
			</section>
			
		</div>
		
	</div>
</div>
              
            
!

CSS

              
                // Reset
:root {
	box-sizing: border-box;
}

*,
*::before,
*::after {
	box-sizing: inherit;
}

// Web Fonts
.font-bold {
	font-family: itc-avant-garde-gothic-pro, sans-serif;
	font-weight: 700;
	font-style: normal;
}
.font-medium {
	font-family: itc-avant-garde-gothic-pro, sans-serif;
	font-weight: 500;
	font-style: normal;
}
.font-book {
	font-family: itc-avant-garde-gothic-pro, sans-serif;
	font-weight: 300;
	font-style: normal;
}

.font-slant {
	// -moz-font-feature-settings: "ss01";
	// -webkit-font-feature-settings: "ss01";
	// font-feature-settings: "ss01";
	-moz-font-feature-settings: "salt";
	-webkit-font-feature-settings: "salt";
	font-feature-settings: "salt";
}

// Colors
$green: #88CE02;
$dark: #121212;

// 

body {
	background-color: #222;
	font-family: itc-avant-garde-gothic-pro,sans-serif;
	font-weight: 300;
	font-style: normal;
	color: $dark;
}

#content {
	display: flex;
	justify-content: center;
	height: 197vh;
	background-image:
		linear-gradient(rgba(255,255,255,.07) 2px, transparent 2px),
		linear-gradient(90deg, rgba(255,255,255,.07) 2px, transparent 2px),
		linear-gradient(rgba(255,255,255,.06) 1px, transparent 1px),
		linear-gradient(90deg, rgba(255,255,255,.06) 1px, transparent 1px);
	background-size: 100px 100px, 100px 100px, 20px 20px, 20px 20px;
	background-position: -2px -2px, -2px -2px, -1px -1px, -1px -1px;
}

// Sections
.sections {
	perspective: 1000px;
	transform-style: preserve-3d;
}

// Section 1
.section-1 {
	position: relative;
	z-index: 1;
	width: 90vw;
	min-height: calc(100vh + 5vw);
	margin-top: 5vw;
	background-color: $green;
	border-radius: 12px;

	.c-title {
		display: flex;
		align-items: center;
		justify-content: center;
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 100%;
		text-align: center;
		letter-spacing: -0.03em;
		color: $dark;
	}

	.info {
		display: flex;
		align-content: center;
		justify-content: center;
		flex-wrap: wrap;
		position: relative;
		transform: translateY(-100%);
	}

	.sub-title {
		position: relative;
		margin-top: 3.6vw;
		font-size: 2vw;
	}

	.title {
		overflow: hidden;
		line-height: 1.4;
	}

	.title-1 {
		padding: 0 0.5ch;
		font-size: clamp(36px, 6.6vw, 154px);
		letter-spacing: -0.05em;
	}

	.title-2 {
		width: 100%;
		margin-top: -1.5vw;
		font-size: clamp(30px, 5.5vw, 129px);
		letter-spacing: -0.04em;
	}
	
	.indicator {
		position: absolute;
		top: 80vh;
		transform: translateY(-100%);
		font-size: clamp(48px, 5.5vw, 129px);
		opacity: 0;
		visibility: hidden;
	}
	
	.pointer {
		animation: pointDown 2.5s infinite;
	}
	
	@keyframes pointDown {
		0% {
			transform: translateY(0);
		}
		10% {
			transform: translateY(20px);
		}
		20% {
			transform: translateY(0);
		}
		30% {
			transform: translateY(20px);
		}
		40% {
			transform: translateY(0);
		}
	}

	.credit {
		position: absolute;
		bottom: 5vw;
		z-index: 1;
		color: $dark;
		letter-spacing: 0.01em;

		a {
			color: $dark;
		}
	}
	
}

// Section 2
.section-2 {
	display: flex;
	align-content: center;
	justify-content: center;
	flex-wrap: wrap;
	position: relative;
	width: 90vw;
	min-height: 100vh;
	font-size: clamp(24px, 4.4vw, 103px);
	letter-spacing: -0.04em;
	text-align: center;
	color: #fff;
	
	.info {
		transform: translateY(-50%);
	}
	
	.text {
		width: 100%;
		margin-bottom: 5px;
	}
		
	a {
		color: $green;
	}
}
              
            
!

JS

              
                gsap.registerPlugin(ScrollTrigger, ScrollSmoother);
gsap.config({ trialWarn: false });

console.clear();

// 

const wrapper = document.querySelector('#wrapper');
const content = document.querySelector('#content');

const sections = document.querySelector('.sections');
const section1 = document.querySelector('.section-1');

let winWidth = window.innerWidth;

let smoother, observer, direction;

// 

// Desktop Only
if (!ScrollTrigger.isTouch !== 1) {
	// ScrollSmoother
	smoother = ScrollSmoother.create({
		wrapper: wrapper,
		content: content,
		smooth: 0.8,
		effects: true
	}).paused(true);
}

// Observer
function initObserver() {
	observer = Observer.create({
		target: document.body,
		ignore: '[data-ignore]',
		type: 'pointer',
		onToggleY: (self) => {
			updateDirection(self);
		},
		onPress: (self) => {
			gsap.set(content, {
				cursor: 'grabbing'
			});
			
			updateDirection(self, true);

			gsap.to('body', {
				backgroundColor: '#111',
				duration: 0.5
			});
			gsap.to(section1, {
				scale: 0.97,
				duration: 0.5
			});
		},
		onRelease: (self) => {
			gsap.set(content, {
				cursor: 'grab'
			});

			gsap.to(section1, {
				rotateX: '0deg'
			});
			gsap.to('body', {
				backgroundColor: '#222',
				duration: 0.5
			});
			gsap.to(section1, {
				scale: 1,
				duration: 0.5
			});
		},
		tolerance: 10
	});
}

// Update Direction (and perspective-origin)
function updateDirection(theObserver, immediate = false) {
	const perspectiveOriginX = Math.floor(100 - theObserver.startX / winWidth * 100);
	const perspectiveOriginY = Math.floor(smoother.scrollTrigger.animation.progress() * 100);
	
	if (immediate) {
		gsap.set(sections, {
			perspectiveOrigin: `${perspectiveOriginX}% ${perspectiveOriginY}%`
		});
	} else {
		gsap.to(sections, {
			perspectiveOrigin: `${perspectiveOriginX}% ${perspectiveOriginY}%`,
			duration: 0.5
		});
	}
	
	direction = (theObserver.deltaY < 0 ? 'up' : 'down');
	
	// Direction for drag is inversed
	if (direction === 'up') {
		gsap.to(section1, {
			rotateX: '3deg',
			duration: 0.5
		});
	} else if (direction === 'down') {
		gsap.to(section1, {
			rotateX: '-3deg',
			duration: 0.5
		});
	}
}

// 

// Section 1 Animations
const introTl = gsap.timeline();

introTl.fromTo(section1, {
	transformOrigin: 'center bottom',
	autoAlpha: 0,
	yPercent: 50
}, {
	autoAlpha: 1,
	yPercent: 0,
	duration: 1,
	delay: 1,
	ease: 'expo'
})
.from('.title-1 .title-text', {
	yPercent: 100,
	duration: 1,
	ease: 'power3'
}, 1.5)
.from('.title-2 .title-text', {
	autoAlpha: 0,
	duration: 1.5
}, 2)
.from('.sub-title-1', {
	autoAlpha: 0,
	x: 30,
	duration: 0.5,
	ease: 'power3'
}, '-=1')
.from('.sub-title-2', {
	autoAlpha: 0,
	x: -30,
	duration: 0.5,
	ease: 'power3'
}, '-=1')
.from('.credit', {
	autoAlpha: 0,
	duration: 0.3,
	onComplete: () => {
		initPage();
	}
}, '-=1');

// Section 2 Animations
gsap.fromTo('.section-2 .info', {
	autoAlpha: 0,
}, {
	autoAlpha: 1,
	duration: 2,
	scrollTrigger: {
		scrub: true,
		trigger: '.section-2 .info',
		start: 'center 80%',
		end: 'center center',
		// markers: true
	}
});

// 

// Init Page
function initPage() {
	if (smoother) {
		ScrollTrigger.normalizeScroll({
			ignore: '[data-ignore]',
			type: 'pointer,wheel'
		});
		smoother.paused(false);
		initObserver();
	}

	gsap.set(content, {
		cursor: 'grab'
	});

	gsap.to('.indicator', {
		autoAlpha: 1,
		duration: 1,
		onComplete: () => {
			gsap.fromTo('.indicator', {
				autoAlpha: 1,
			}, {
				autoAlpha: 0,
				duration: 1,
				scrollTrigger: {
					scrub: true,
					trigger: '.indicator',
					start: 'center 80%',
					end: 'center 70%',
					// markers: true
				}
			});
		}
	});
}

//

// Resize
function onResize() {
	winWidth = window.innerWidth;
	ScrollTrigger.refresh();
}

window.addEventListener('resize', onResize);

// 

// Web development credit via console log
console.log('%c%s', 'border-radius: 6px; padding: 8px; color: #ffffff; background: #4801ff;','✨ Developed by: Van Holtz Co — https://vanholtz.co');
              
            
!
999px

Console