HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="canvasStage"></div>
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;
}
/*
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;
}
Also see: Tab Triggers