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

              
                <button data-button>Animate</button>
<figure class="item">
	<div class="box-col">
		<div class="box" data-box></div>
	</div>
	<figcaption class="desc">
		<h3>Normal direction animation</h3>
		<p>We want the boxes to each have the same easing!</p>
	</figcaption>
</figure>
<figure class="item">
	<div class="box-col">
		<div class="box box--reverse" data-reverse></div>
	</div>
	<figcaption class="desc">
		<h3>Reverse direction animation</h3>
		<p><code>animation-timing-function</code> (easing) is reversed when <code>animation-direction</code> is set to <code>reverse</code>.</p>
	</figcaption>
</figure>
<figure class="item">
	<div class="box-col">
		<div class="box box--corrected" data-corrected></div>
	</div>
	<figcaption class="desc">
		<h3>Corrected animation</h3>
		<p>Instead of reversing the animation we need to create a new keyframe animation for the correct easing to apply.</p>
	</figcaption>
</figure>

              
            
!

CSS

              
                * {
	box-sizing: border-box;
}

body {
	padding: 20px;
	background-color: #37474F;
}

button {
	padding: 10px 20px;
	border-radius: 0.3em;
	border: none;
	background-color: #5ca9d6;
	cursor: pointer;
	
	&:hover,
	&:focus {
		background-color: darken(#5ca9d6, 20%);
	}
	
	&:disabled {
		opacity: 0.4;
		pointer-events: none;
	}
}

.item {
	display: flex;
	flex-wrap: wrap;
	max-width: 1200px;
	margin: 20px auto;
	padding: 20px;
	background-color: #ebf3f4;
	border-radius: 0.5em;
}

.box-col {
	width: 700px;
	flex: 0 0 auto;
	margin: 0;
}

.desc {
	width: 400px;
	flex: 0 1 auto;
}

.box {
	--e1: 0.420;
	--e2: 0.150;
	--e3: 0.220;
	--e4: 1.015;
	
	--e1-r: calc(1 - var(--e3));
	--e2-r: calc(1 - var(--e4));
	--e3-r: calc(1 - var(--e1));
	--e4-r: calc(1 - var(--e2));
	
	--normal: cubic-bezier(var(--e1), var(--e2), var(--e3), var(--e4));
	
	--reverse: cubic-bezier(var(--e1-r), var(--e2-r), var(--e3-r), var(--e4-r));
	
	width: 100px;
	height: 100px;
	background-color: #ED1DD9;
	
	&.is-animating {
		animation: slide 3000ms var(--normal) forwards;
	}
	
	&.is-animating-reverse {
		animation: slide 3000ms var(--normal) reverse forwards;
	}
	
	&.is-animating-corrected {
		animation: slide 3000ms var(--reverse) reverse forwards;
	}
}

.box--reverse {
	background: #3d63ed;
	transform: translate3d(500px, 0, 0);
}

.box--corrected {
	background: #3ceab6;
	transform: translate3d(500px, 0, 0);
}

@keyframes slide {
	from {
		transform: translate3d(0, 0, 0);
	}
	
	to {
		transform: translate3d(500px, 0, 0);
	}
}
              
            
!

JS

              
                const btn = document.querySelector('[data-button]')
const boxes = [...document.querySelectorAll('.box')]
const box1 = document.querySelector('[data-box]')
const box2 = document.querySelector('[data-reverse]')
const box3 = document.querySelector('[data-corrected]')

const addAnimation = (el, className) => {
	el.classList.add(className)
	
	setTimeout(() => {
		el.classList.remove(className)
		btn.disabled = false
	}, 3200)
}

const animateBoxes = (e) => {
	e.target.disabled = true
	addAnimation(box1, 'is-animating')
	addAnimation(box2, 'is-animating-reverse')
	addAnimation(box3, 'is-animating-corrected')
}

btn.addEventListener('click', animateBoxes)
              
            
!
999px

Console