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="container"></div>

<a href="https://codepen.io/hallonanton/" target="_blank" class="more">More 🔥 pens</a>
              
            
!

CSS

              
                /*
 * Standard Styles
 */
@import url("https://fonts.googleapis.com/css?family=Source+Sans+Pro:700");

html,
body {
	height: 100%;
	margin: 0px;
	padding: 0px;
	box-sizing: border-box;
	overflow: hidden;
	background-color: #383A3F;
	font-family: "Source Sans Pro", sans-serif;
}

#container {
	display: flex;
	justify-content: space-around;
	align-items: center;
	flex-wrap: wrap;
	width: 100%;
	height: 100%;
}

.title {
	text-align: center;
	font-size: 14px;
	color: #fff;
}

.box {
	width: 50px;
	height: 50px;
	margin: 20px auto 0px;
}

/*
 * More from me link 🔥
 */
.more {
	position: absolute;
	bottom: 15px;
	right: 15px;
	padding: 7px 21px;
	border-radius: 8px;
	color: #fff;
	background-color: rgba(0,0,0,.2);
	font-size: 0.7rem;
	font-weight: 700;
	text-transform: uppercase;
	text-decoration: none;
	overflow: hidden;
	z-index: 1;
	animation: reveal 5000ms cubic-bezier(.87,-.41,.19,1.44);
	
	&::before {
		display: block;
		content: "";
		position: absolute;
		top: 50%;
		left: 50%;
		width: 100%;
		max-width: 20%;
		height: 100%;
		border-radius: 8px;
		background-color: rgba(0,0,0,0);
		transition: max-width 0ms ease 250ms,
						background-color 250ms ease;
		transform: translate(-50%, -50%);
		z-index: -1;
	}
	
	&:hover {
		&::before {
			max-width: 100%;
			background-color: rgba(0,0,0,0.6);
			transition: all 250ms ease;
		}
	}
}

@keyframes reveal {
    0%, 90% {
		 bottom: -30px;
	}
   100% {
		 bottom: 15px;
	}
}
              
            
!

JS

              
                //Animation variables
var duration = 3000; //MS
var framesPerSec = 60;
var totalSec = duration/1000;
var steps = Math.floor(totalSec*framesPerSec);


//Vanilla JS easings 
//Copied from https://gist.github.com/gre/1650294
EasingFunctions = {
  // no easing, no acceleration
  linear: function (t) { return t },
  // accelerating from zero velocity
  easeInQuad: function (t) { return t*t },
  // decelerating to zero velocity
  easeOutQuad: function (t) { return t*(2-t) },
  // acceleration until halfway, then deceleration
  easeInOutQuad: function (t) { return t<.5 ? 2*t*t : -1+(4-2*t)*t },
  // accelerating from zero velocity 
  easeInCubic: function (t) { return t*t*t },
  // decelerating to zero velocity 
  easeOutCubic: function (t) { return (--t)*t*t+1 },
  // acceleration until halfway, then deceleration 
  easeInOutCubic: function (t) { return t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1 },
  // accelerating from zero velocity 
  easeInQuart: function (t) { return t*t*t*t },
  // decelerating to zero velocity 
  easeOutQuart: function (t) { return 1-(--t)*t*t*t },
  // acceleration until halfway, then deceleration
  easeInOutQuart: function (t) { return t<.5 ? 8*t*t*t*t : 1-8*(--t)*t*t*t },
  // accelerating from zero velocity
  easeInQuint: function (t) { return t*t*t*t*t },
  // decelerating to zero velocity
  easeOutQuint: function (t) { return 1+(--t)*t*t*t*t },
  // acceleration until halfway, then deceleration 
  easeInOutQuint: function (t) { return t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t }
}


//Function to get a easing
function getEasing(i) {
	i = i || 0;
	
	var easingArray = Object.keys(EasingFunctions);

	return easingArray[i%easingArray.length];
}


//Function to get a color
function getColor(i) {
	i = i || 0;
	
	var colorArray = [
		'#F68657',
		'#8CD790',
		'#A593E0',
		'#FFBC42',
		'#4FB0C6',
		'#F16B6F'
	];
	
	return colorArray[i%colorArray.length];
}


//Box object	
function Box(color, easing) {
	
	this.easing = easing || 'linear';
	this.color = color || 'blue';
	
	//Create box
	this.add = function () {
		
		var container = document.getElementById('container');
		
		var boxContainer = document.createElement('div');
		
		var title = document.createElement('div');
		title.classList.add(['title']);
		title.innerHTML = this.easing;
		
		var box = document.createElement('div');
		box.classList.add(['box']);
		box.style.background = this.color;
		box.title = this.easing;
		box.addEventListener('mouseover', animate);
		
		boxContainer.append(title);
		boxContainer.append(box);
		container.append(boxContainer);
	}
}


//Create boxes
var boxQuantity = Object.keys(EasingFunctions).length;
for (var i = 0; i < boxQuantity; i++) {
	var color = getColor(i);
	var easing = getEasing(i);
	var box = new Box(color, easing);
	box.add();
}


//Animate
function animate(event) {
	
	var easing = event.target.title;
	
	var boxObject = {
		target: event.target,
		easing: EasingFunctions[easing],
		itterations: steps,
		progress: 0,
		deg: 0,
	}
	
	animationLoop(boxObject);
}

function animationLoop(boxObject) {
	
	boxObject.itterations--;
	boxObject.progress = 1 - (boxObject.itterations/steps);
	
	/**This is where the easing is applied**/
	boxObject.deg = 360*boxObject.easing( boxObject.progress );
	
	boxObject.target.style.transform = "rotate("+boxObject.deg+"deg)";
		
   setTimeout(function() {	
      if (boxObject.itterations) {
			animationLoop(boxObject);
		}
   }, (duration/steps));
}
              
            
!
999px

Console