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:relative;
	width:250px;
	height:250px;
}
#canvasStage canvas{
	position:absolute;
	display:block;
	margin:0;
	padding:0;
}
              
            
!

JS

              
                console.clear()
var log = console.log.bind(console)

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

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

for (var i = 0; i < 8; i++) {
	var myEl = (canvasElement+"_"+i);
	// var myC = '<canvas id="' + myEl + '" width="106" height="106"></canvas>';
  
  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);
	// holder1.append($(myC));
	// var element1 = document.querySelector("#"+myEl);
	// var context = element1.getContext("2d");
	context.beginPath();
	context.moveTo(51, 3);
	context.lineTo(3, 103);
	context.lineTo(103, 103);
	context.closePath();
	// the outline
	context.lineWidth = 5;
	context.strokeStyle = '#444';
	context.stroke();
	// the fill color
	context.fillStyle = "#00F";
	context.fill();
}
//
/*
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
*/

var tl = new TimelineMax({ onStart: updateCube, repeat:-1, smoothChildTiming:true})

var triangles = $("#canvasStage canvas");
	myHolder = $("#canvasStage"),
    // tl = new TimelineMax({onUpdate:updateCube, repeat:-1, smoothChildTiming:true}),
	stageW = ($(window).width())/2,
	stageH = ($(window).height())/2,
	stageX = (stageW-(106/2)),
	stageY = (stageH-(106/2));
//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:"52px 52px 52px"}});
// TweenLite.set(myHolder, {rotationY:0, rotationX:0, x:0, y:0, transformOrigin:"52px 52px 52px"});

//
tl.set(triangles[0], {rotationX:30.5, rotationY:0, rotationZ:0, x:0, y:2, z:52, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[1], {rotationX:30.5, rotationY:0, rotationZ:180, x:0, y:-2, z:52, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[2], {rotationX:30.5, rotationY:90, rotationZ:0, x:52, y:2, z:0, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[3], {rotationX:30.5, rotationY:270, rotationZ:180, x:52, y:-2, z:0, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[4], {rotationX:30.5, rotationY:-90, rotationZ:0, x:-52, y:2, z:0, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[5], {rotationX:30.5, rotationY:-270, rotationZ:180, x:-52, y:-2, z:0, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[6], {rotationX:30.5, rotationY:180, rotationZ:0, x:0, y:2, z:-52, opacity:0.85, transformOrigin:"50% 100%"})
  .set(triangles[7], {rotationX:30.5, rotationY:180, rotationZ:180, x:0, y:-2, z:-52, opacity:0.85, transformOrigin:"50% 100%"})
  // .set(myHolder, {rotationY:0, rotationX:0, x:0, y:0, transformOrigin:"52px 52px 52px"});

//
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, transformOrigin:"52px 52px 52px"}, ease:Power0.easeNone});
for (var i = 0; i < 8; i++) {
	TweenMax.to(triangles[i], 2, {rotationX:-24, transformOrigin:"50% 100%", repeat:-1, yoyo:true, repeatDelay:2,  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));
	TweenMax.to(myHolder, 3, {css:{x:stageX, y:stageY}});
  
  // Clear request
  requestId = null;
}
              
            
!
999px

Console