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

CSS

              
                body {background-color:black; color:#FFF;}
#canvasStage {
	position:absolute;
	width:106px;
	height:106px;
}
#canvasStage2 {
	position:absolute;
	width:56px;
	height:56px;
}
#canvasStage canvas{
	position:absolute;
	display:block;
	margin:0;
	padding:0;
}
#canvasStage2 canvas{
	position:absolute;
	display:block;
	margin:0;
	padding:0;
}
              
            
!

JS

              
                /*
This animation by FlawlessDog.com

Made possible by GreenSock Animation Platform (GSAP) v12 beta.
https://www.greensock.com/gsap-js/

This effect works great in modern browsers: Chrome, Safari, and FireFox.

IE does not support transform-style:preserve3d, so the 3D may look a little flat. 
Once again IE proves its ability to hinder progress and inflict pain on developers.
https://msdn.microsoft.com/en-us/library/ie/hh673529(v=vs.85).aspx#_3dtranslate
*/
console.clear()
var log = console.log.bind(console)

var canvasElement = "myCanvas";
var canvasHolder = "canvasStage";
var holder1 = $("#"+canvasHolder);//

var canvasElement2 = "myCanvas2";
var canvasHolder2 = "canvasStage2";


var resolution = window.devicePixelRatio || 1;
var requestId = null;

for (var i = 0; i < 20; i++) {
	var myEl = (canvasElement+"_"+i);
	var canvas = document.createElement("canvas");
	var context = canvas.getContext("2d");
	// Scale canvas to match pixel ratio for HiDPI screens
	canvas.id = myEl;
	canvas.width  = 106 * resolution;
	canvas.height = 106 * resolution;
	canvas.style.width  = 106 + "px";
	canvas.style.height = 106 + "px";
	context.scale(resolution, resolution);
	holder1.append(canvas);
	//New Shape	
	context.beginPath();
	//main shape
	context.moveTo(51, 3);
	context.lineTo(103, 103);
	context.lineTo(3, 103);
	context.closePath();
	//the hole
	context.moveTo(28, 88);
	context.lineTo(78, 88);
	context.lineTo(51, 28);
	context.closePath();
	// the outline
	context.lineWidth = 5;
	context.strokeStyle = '#444';
	context.stroke();
	// the fill color
	context.fillStyle = "#00F";
	context.fill();
}
//
var myDiv = "<div id='canvasStage2'></div>";
holder1.append($(myDiv));
var holder2 = $("#"+canvasHolder2);//
//
for (var i = 0; i < 6; i++) {
	var myEl2 = (canvasElement2+"_"+i);
	var canvas2 = document.createElement("canvas");
	var context2 = canvas2.getContext("2d");
	// Scale canvas to match pixel ratio for HiDPI screens
	canvas2.id = myEl2;
	canvas2.width  = 56 * resolution;
	canvas2.height = 56 * resolution;
	canvas2.style.width  = 56 + "px";
	canvas2.style.height = 56 + "px";
	context2.scale(resolution, resolution);
	holder2.append(canvas2);
	//New Shape	
	context2.beginPath();
	//main shape
	context2.moveTo(3, 3);
	context2.lineTo(3, 53);
	context2.lineTo(53, 53);
	context2.lineTo(53, 3);
	context2.closePath();
	// the outline
	context2.lineWidth = 5;
	context2.strokeStyle = '#444';
	context2.stroke();
	// the fill color
	context2.fillStyle = "#F0F";
	context2.fill();
}
//
var tl = new TimelineMax({ onStart: updateCube, repeat:-1, smoothChildTiming:true})
var triangles = $("#canvasStage canvas");
var	myHolder = $("#canvasStage");
//
var tl2 = new TimelineMax({repeat:-1, smoothChildTiming:true})
var squares = $("#canvasStage2 canvas");
var	myHolder2 = $("#canvasStage2");
//transformPerspective gives the element its own vanishing point
//perspective allows all the child elements (orange boxes) to share the same vanishing point with each other
//transformStyle:"preserve3d" allows the child elements to maintain their 3D position (noticeable only when their parent div is rotated in 3D space)
TweenMax.set(myHolder, {css:{transformPerspective:4000, transformStyle:"preserve-3d", transformOrigin:"0px 0px 0px"}});
TweenMax.set(myHolder2, {css:{transformPerspective:4000, transformStyle:"preserve-3d", x:25, y:-25, z:0, transformOrigin:"50% 50% 0%"}});
//
tl.set(triangles[0], {rotationX:43, rotationY:36, rotationZ:0, x:0, y:-128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[1], {rotationX:43, rotationY:108, rotationZ:0, x:0, y:-128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[2], {rotationX:43, rotationY:180, rotationZ:0, x:0, y:-128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[3], {rotationX:43, rotationY:252, rotationZ:0, x:0, y:-128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[4], {rotationX:43, rotationY:324, rotationZ:0, x:0, y:-128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  //
  .set(triangles[5], {rotationX:-9, rotationY:0, rotationZ:0, x:0, y:-52, z:71, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[6], {rotationX:-9, rotationY:-36, rotationZ:180, x:50, y:52, z:71, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[7], {rotationX:-9, rotationY:72, rotationZ:0, x:68, y:-52, z:20, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[8], {rotationX:-9, rotationY:-108, rotationZ:180, x:84, y:52, z:-27, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[9], {rotationX:-9, rotationY:144, rotationZ:0, x:40, y:-52, z:-57, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[10], {rotationX:-9, rotationY:180, rotationZ:180, x:0, y:52, z:-87, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[11], {rotationX:-9, rotationY:-144, rotationZ:0, x:-44, y:-52, z:-55, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[12], {rotationX:-9, rotationY:108, rotationZ:180, x:-84, y:52, z:-27, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[13], {rotationX:-9, rotationY:-72, rotationZ:0, x:-67, y:-52, z:24, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[14], {rotationX:-9, rotationY:36, rotationZ:180, x:-52, y:52, z:71, opacity:0.85, transformOrigin:"50% 0%"})
  //
  .set(triangles[15], {rotationX:137, rotationY:0, rotationZ:0, x:0, y:128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[16], {rotationX:137, rotationY:72, rotationZ:0, x:0, y:128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[17], {rotationX:137, rotationY:144, rotationZ:0, x:0, y:128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[18], {rotationX:137, rotationY:216, rotationZ:0, x:0, y:128, z:0, opacity:0.85, transformOrigin:"50% 0%"})
  .set(triangles[19], {rotationX:137, rotationY:288, rotationZ:0, x:0, y:128, z:0, opacity:0.85, transformOrigin:"50% 0%"});
//
//
tl2.set(squares[0], {rotationX:0, rotationY:0, x:0, y:0, z:26.5, opacity:0.85, transformOrigin:"50% 50%"})
   .set(squares[1], {rotationX:0, rotationY:-90, x:-26.5, y:0, z:0, opacity:0.85, transformOrigin:"50% 50%"})
   .set(squares[2], {rotationX:0, rotationY:90, x:26.5, y:0, z:0, opacity:0.85, transformOrigin:"50% 50%"})
   .set(squares[3], {rotationX:90, rotationY:0, x:0, y:-26.5, z:0, opacity:0.85, transformOrigin:"50% 50%"})
   .set(squares[4], {rotationX:-90, rotationY:0, x:0, y:26.5, z:0, opacity:0.85, transformOrigin:"50% 50%"})
   .set(squares[5], {rotationX:0, rotationY:180, x:0, y:0, z:-26.5, opacity:0.85, transformOrigin:"50% 50%"});
//
//This one seemed impresive enough without the mouseover.
/*
triangles.each(function (index, element) {
   
  var hoverTween = TweenMax.to(element, 0.15, {opacity:0.33, paused: true });
  
			$(element).hover(over, out);
			function over(){
        hoverTween.play();
				// TweenMax.to(element, 0.15, {opacity:0.33});
			}
			function out(){
        hoverTween.reverse();
				// TweenMax.to(element, 0.15, {opacity:0.85});
			}
});
*/
//
tl.to(myHolder, 15, {css:{rotationY:720, rotationX:360, rotationZ:-360}, ease:Power0.easeNone});
tl2.to(myHolder2, 15, {css:{rotationY:-720, rotationX:-360, rotationZ:360}, ease:Power0.easeNone});

$(window).resize(function() {
						  
  // If there's not a pending request, create one
  if (!requestId) {
    requestId = requestAnimationFrame(updateCube);
  }
});

//
function updateCube(){
	stageW = ($(window).width())/2;
	stageH = ($(window).height())/2;
	//stageX = (stageW-(106/2));
	//stageY = (stageH-(106/2));
	//Changed the destination as it seems not to need the extra formula for full centering
	TweenMax.to(myHolder, 3, {css:{x:stageW, y:stageH}});
	// Clear request
	requestId = null;
}
              
            
!
999px

Console