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

              
                <input type="button" value="translate" id="translate">
<input type="button" value="rotate" id="rotate">

<div id="blue"></div>
<div id="green"></div>
<div id="orange"></div>
<div id="purple"></div>
              
            
!

CSS

              
                * {
	padding: 0;
	margin: 0;
}
div {
    position: absolute;
    width: 50px;
    height: 50px;
    left: 50px;
    top: 50px;
}
#blue {
	background-color: blue;
}
#green {
	background-color: green;
	top: 150px;
}
#orange {
	background-color: orange;
	top: 250px;
}
#purple {
	background-color: purple;
	top: 350px;
}
              
            
!

JS

              
                var durationInSeconds = 5.0;

var omega = 20;
var zeta = 0.5;

var oldX = 0;
var oldY = 0;
var oldR = 0;
var oldS = 1;

var translated = false;
var rotated = false;
var shiftKeyPressed = false;

var blue = document.getElementById("blue");
var green = document.getElementById("green");
var orange = document.getElementById("orange");
var purple = document.getElementById("purple");

if (blue) { // added backwards to show animations are properly sorted by index
	blue.hyperAnimate(constantRotateAnimation(0),"underlyingRotate");
	blue.hyperAnimate(constantScaleAnimation(1),"underlyingScale");
	blue.hyperAnimate(constantTranslateAnimation(0,0),"underlyingTranslate");
}

if (orange) orange.setHyperDefaultAnimations({
	transform : { // animation description
		duration: animationDuration(),
		easing: easing,
	}
});

function PurpleDelegate() { }
PurpleDelegate.prototype = {
	hyperAnimationForKey: function(key) {
		return { // animation description
			duration: animationDuration(),
			easing: easing,
		}
	}
}
var purpleDelegate = new PurpleDelegate();
if (purple) purple.setHyperAnimationDelegate(purpleDelegate);

document.addEventListener("keydown",toggleShiftKey,false);
document.addEventListener("keyup",toggleShiftKey,false);
document.getElementById("translate").addEventListener("click",toggleTranslate,false);
document.getElementById("rotate").addEventListener("click",toggleRotate,false);

function animationDuration() { // in seconds!
	return durationInSeconds * ((shiftKeyPressed) ? 5.0 : 1.0);
}

function easing(position) {
	var beta = Math.sqrt(1.0 - zeta * zeta);
	var value = 1.0 / beta * Math.exp(-zeta * omega * position) * Math.sin(beta * omega * position + Math.atan(beta / zeta));
	return 1-value;
}

function toggleShiftKey(e) {
	shiftKeyPressed = e.shiftKey;
	
	if (orange) orange.setHyperDefaultAnimations({ // have to update animation duration on shift key press
		transform : { // animation description
			duration: animationDuration(),
			easing: easing,
		}
	});
}

function toggleTranslate() {
	translated = !translated;
	var newX = 0;
	if (translated) newX = 200;
	translateToPoint(newX,0);
	oldX = newX;
}

function toggleRotate() {
	rotated = !rotated;
	var newR = 0;
	var newS = 1;
	if (rotated) {
		newR = 180;
		newS = 1.5;
	}
	rotateAndScale(newR,newS);
	oldR = newR;
	oldS = newS;
}

function constantRotateAnimation(value) { // for blue div
	return { // animation description
		type:"transform",
		from:"rotate("+value+"deg)",
		to:"rotate("+value+"deg)",
		ink:"absolute",
		index:3,
		fill:"forwards",
		composite:"add"
	}
}
function constantScaleAnimation(value) { // for blue div
	return { // animation description
		type:"transform",
		from:"scale("+value+")",
		to:"scale("+value+")",
		ink:"absolute",
		index:2,
		fill:"forwards",
		composite:"add"
	}
}
function constantTranslateAnimation(x,y) { // for blue div
	return { // animation description
		type:"transform",
		from:"translate3d("+x+"px,"+y+"px,0)",
		to:"translate3d("+x+"px,"+y+"px,0)",
		ink:"absolute",
		index:1,
		fill:"forwards",
		composite:"add"
	}
}

function rotateAndScale(newR,newS) {
	var duration = animationDuration();
	
	if (blue) {
		blue.hyperAnimate(constantRotateAnimation(newR),"underlyingRotate");
		blue.hyperAnimate(constantScaleAnimation(newS),"underlyingScale");
		blue.hyperAnimate({ // animation description
			type:"transform",
			from:"rotate("+oldR+"deg)",
			to:"rotate("+newR+"deg)",
			duration:duration,
			easing:easing,
			index:3,
		});
		blue.hyperAnimate({ // animation description
			type:"transform",
			from:"scale("+oldS+")",
			to:"scale("+newS+")",
			duration:duration,
			easing:easing,
			index:2,
		});
	}
	
	if (green) {
		green.hyperAnimate({ // animation description
			type:"transform",
			from:"translate3d("+oldX+"px,"+oldY+"px,0) scale("+oldS+") rotate("+oldR+"deg)",
			to:"translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)",
			duration:duration,
			easing:easing,
		});
		green.style.transform = "translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)";
		green.style.webkitTransform = "translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)";
	}
	
	if (orange) {
		orange.style.transform = "translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)";
		orange.style.webkitTransform = "translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)";
	}
	
	if (purple) {
		purple.style.transform = "translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)";
		purple.style.webkitTransform = "translate3d("+oldX+"px,"+oldY+"px,0) scale("+newS+") rotate("+newR+"deg)";
	}
}

function translateToPoint(newX,newY) {
	var duration = animationDuration();
	
	if (blue) {
		blue.hyperAnimate(constantTranslateAnimation(newX,newY),"underlyingTranslate");
		blue.hyperAnimate({ // animation description
			type:"transform",
			from:"translate3d("+oldX+"px,"+oldY+"px,0)",
			to:"translate3d("+newX+"px,"+newY+"px,0)",
			duration:duration,
			easing:easing,
			index:1,
		});	
	}

	if (green) {
		green.hyperAnimate({ // animation description
			type:"transform",
			from:"translate3d("+oldX+"px,"+oldY+"px,0) scale("+oldS+") rotate("+oldR+"deg)",
			to:"translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)",
			duration:duration,
			easing:easing,
		});	
		green.style.transform = "translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)";
		green.style.webkitTransform = "translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)";
	}

	if (orange) {
		orange.style.transform = "translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)";
		orange.style.webkitTransform = "translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)";
	}
	
	if (purple) {
		purple.style.transform = "translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)";
		purple.style.webkitTransform = "translate3d("+newX+"px,"+newY+"px,0) scale("+oldS+") rotate("+oldR+"deg)";
	}
}
              
            
!
999px

Console