Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="container">
	<div class="scene">
		<div class="word">
			<div class="face" data-face="face--1">
				<p class="txt" data-txt="txt--1">gsap
				</p>
			</div>
		</div>
	</div>
</div>

<div class="collection">
	<a class="collection__link" href="https://codepen.io/collection/02388423440b98155f8e4002bde094f2" target='_blank'>The GSAP 3 collection<span></span></a>
</div>

<a href="https://greensock.com" target="_blank"><img class="gsap-3-logo" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/16327/gsap-3-logo.svg" width="150" /></a>

            
          
!
            
              @font-face {
	font-family: 'Anybody';
	src: url('https://s3-us-west-2.amazonaws.com/s.cdpn.io/61488/ETCAnybodyPB.woff2') format('woff2-variations');
	font-display: block;
	font-style: normal italic;
	font-weight: 100 900;
	font-stretch: 10% 400%;
}

:root {
	--fontSize: 140px;
}


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

body,
html {
	height: 100%;
	width: 100%;
	margin: 0;
	padding: 0;
}

body {
	background: #000;
	// background-image: radial-gradient(farthest-side at 45vw 0vh, rgba(255,255,255, 0.2) 0%, #101010 100%);
	font-family: 'Anybody', Helvetica, sans;
	color: white;
	overflow: hidden;
}

.container {
	display: flex;
	align-items: center;
	justify-content: center;
	height: 100%;
	perspective: 900px;
	visibility: hidden;
	opacity: 0;
}

.scene {
	position: relative;
	transform-style: preserve-3d;
}

.word {
	transform-style: preserve-3d;
}

.face {
	position: absolute;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	transform-style: preserve-3d;
	// border: 2px solid white;
}

.txt {
	margin: 0;
	transform-style: preserve-3d;
	font-size: calc(3*var(--fontSize));
	font-weight: 900;
	font-stretch: 10%;
	font-style: normal;
	text-transform: uppercase;
	line-height: 0.73;
	text-align: center;
}

.gsap-3-logo {
	width: 20vw;
	max-width: 150px;
	position: fixed;
	bottom: 15px;
	right: 15px;
}

/*  ==========================================================
	Collection Linl
	========================================================== */

.collection {
	position: fixed;
	z-index: 1000;
	top: 24px;
	right: 24px;
	display: flex;
	flex-direction: column;
}

.collection__link {
	position: relative;
	margin-bottom: 16px;
	color: white;
	font-family: Helvetica, sans-serif;
	text-decoration: none;
	font-size: 16px;

	span {
		display: block;
		position: absolute;
		bottom: -3px;
		left: 0;
		height: 1px;
		width: 10%;
		background-color: white;
		content: "";
		transition: width 0.3s;
	}

	&:hover span{
		width: 100%;
	}
}
            
          
!
            
              console.clear();

select = e => document.querySelector(e);

const txt = select('.txt');
const scene = select('.scene');
const face = select('.face');
const numSteps = 8;
const stepHeight = 100/numSteps;
const stepAngle = 75;
// let dX = 0;
// let dY = 0;
let clones = [];

function cloneFace() {
	
	for (let i = 0; i < numSteps-1; i++){
		// pop these kids into the clones array. numSteps-1 'cause 1 already exists in the DOM
		clones.push(face.cloneNode(true));
	}
	
	let parentFace = face; // the original
	let parentTxt = txt; // the original
	
	clones.forEach( (clone,i) => {
		clone.dataset.face = `face--${i + 2}`; // increment the new data attributes
		clone.querySelector('.txt').dataset.txt = `txt--${i + 2}`; // increment the new data attributes
		parentFace.appendChild(clone);
		parentFace = clone; // original is the new black
	});
}

function clipYourFace() {
	for(let i= 0; i<numSteps; i++) {
		let yPos = stepHeight*i;
		gsap.set(`[data-txt="txt--${i+1}"]`, { 
			clipPath: `polygon(0 ${yPos}%, 100% ${yPos}%, 100% ${yPos+stepHeight+0.4}%, 0 ${yPos+stepHeight+0.4}%)`
		});
	}
}


cloneFace();
clipYourFace();

gsap.set('.container', { autoAlpha: 1 });
gsap.set('.scene', { transformOrigin: "center center -400px" });

let gtl = gsap.timeline( { 
	delay: 1,
	repeat: -1, 
	repeatDelay: 0,
	defaults: {
		ease: 'power4.inOut'
	}
});

function stepText(tEase, angle) {
	
	let tl = gsap.timeline();
	
	for (let step = 0; step < numSteps-1; step++){
	
		let dir = -1;

		if(step%2==0) {
			dir=1; // which way am I going? Up or down?
		}
		tl.to(`[data-face="face--${step+2}"]`, {
			rotationX: function() {
				if(angle!=0) {
					angle = stepAngle*dir;
				}
				return angle;
			},
			color: function() {
				let stepColor = "#fff";
				if(step%2==0 && angle!=0) {
					stepColor = "#d7d7d7";
				}
				return stepColor;
			},
			ease: tEase,
			transformOrigin: `50% ${stepHeight*step+stepHeight}%`,
			duration: 1.2
		}, `0.${step}`)
	}
	
	return tl;
}

gtl.add(stepText('elastic', 1))
	.add(stepText('elastic', 0));

function calcOffset(xPos, yPos) {
	let winW = window.innerWidth;
	let winH = window.innerHeight;
	let dX = 2*(xPos - winW/2)/winW;
	let dY = -2*(yPos - winH/2)/winH;
	return [dX,dY];
}

function rotateTxt(xPos, yPos) {
	let nPos = calcOffset(xPos, yPos); // get cursor position from center 1-0-1
	let nX = nPos[0];
	let nY = nPos[1];
	let invertedRangeX = 1-Math.sqrt(nX*nX); // 0-1-0
	let invertedRangeY = 1-Math.sqrt(nY*nY); // 0-1-0
	gsap.to('.scene', {
		rotationX: nPos[1]*30,
		rotationY: nX*30,
		rotation: nX*40,
		duration: 1,
		ease: 'sine'
	})
	gsap.to('.txt', {
		fontStretch: `${(200-200*invertedRangeY)}%`,
		fontWeight: invertedRangeX*900,
		duration: 1
	});
}

var pointer = { 
	x: window.innerWidth  / 2, 
	y: window.innerHeight / 2 
};

window.addEventListener("mousemove", function(event) {
	pointer.x = event.clientX;
	pointer.y = event.clientY;
	rotateTxt(pointer.x, pointer.y);
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console