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 class="frame">
<svg class="stage" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 500 400">
<defs>
<symbol id="chairSide" viewBox="0 0 41 77">
<g class="rightLeg">
<polyline class="cls-1 tint" points="2 75 6 36 2 2"/>
<polyline class="cls-1 tint" points="6 36 37 18 39 51"/>
</g>
</symbol>
<symbol id="headtail" viewBox="0 0 4 24">
<line class="tail cls-2" x1="2" y1="2" x2="2" y2="22"/>
</symbol>
<symbol id="Head" viewBox="0 0 159 73">
<circle class="head" cx="45" cy="10" r="10"/>
<g id="transition">
<use class="trans trans_ghost" width="5" height="20" transform="translate(43 15)" xlink:href="#headtail"/>
<use class="trans trans_trail" width="5" height="20" transform="translate(43 10)" xlink:href="#headtail"/>
</g>
<g id="plane">
<path id="lineWing" class="cls-2" d="M45,11s-8,13-8,26H17L2,47H89l20-5"/>
<path id="lineBase" class="cls-2" d="M22,53l5,18L157,36H73V34c0-2-2-2-4-2L50,34,41,22l4-12"/>
</g>
</symbol>
</defs>
<g class="the_worker">
<g class="the_worker_atdesk">
<path class="rightlowerleg lowerlegs cls-2" d="M226,255l32-5a3,3,0,0,1,3,3v23"/>
<path class="leftlowerleg lowerlegs cls-2" d="M226,255l8-16a1,1,0,0,1,2,0v22"/>
<g class="chair chairLeft">
<use width="41" height="77.06" transform="translate(192 224)" xlink:href="#chairSide"/>
<polygon id="seat" class="cls-3" points="198 260 231 279 262 261 230 242 198 260"/>
</g>
<path class="rightupperleg upperlegs cls-2" d="M226,255L258,250"/>
<path class="leftupperleg upperlegs cls-2" d="M226,255L234,239"/>
<g class="the_worker_torso">
<path class="spine cls-2" d="M236,200c0,10-10,11-10,55"/>
<g class="rightarm">
<line class="mouse cls-1" x1="278" y1="225" x2="281" y2="223"/>
<path class="arm cls-2" d="M232,213c4,2,15,19,15,19h4l26-6"/>
</g>
<path class="leftarm cls-2" d="M232,213c-4-2-2,4-2,4l20-11"/>
<use class="the_worker_head" width="159" height="73" transform="translate(191 190)" xlink:href="#Head"/>
</g>
<g class="chair chairLeft">
<polygon class="back cls-4 tint" points="196 242 228 261 227 245 194 226 196 242"/>
<use width="41" height="77.06" transform="translate(225 243)" xlink:href="#chairSide"/>
</g>
</g>
</g>
</svg>
<form class="controls">
<label><input type="radio" name="state" value="creation"> creation</label>
<label><input type="radio" name="state" value="working"> working</label>
<label><input type="radio" name="state" value="sleep"> sleep</label>
<label><input type="radio" name="state" value="transition"> transition</label>
<label><input type="radio" name="state" value="plane"> plane</label>
<label><input type="radio" name="state" value="flying"> flying</label>
</form>
</div>
// Page setup
html, body {
height: 100%;
}
body {
display: flex;
align-items: center;
justify-content: center;
}
.frame {
background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/96249/desk_reference.png);
background-repeat: no-repeat;
background-position: center center;
background-size: contain;
width: 100vw;
height: 80vw;
}
.stage {
width: 100%;
height: 100%;
}
// SVG styling
.cls-1, .cls-2 { fill: none; }
.cls-1 { stroke: #4d4d4d; }
.cls-1, .cls-2, .cls-3, .cls-4 {
stroke-linecap: round;
stroke-linejoin: round;
stroke-width: 4px;
}
.cls-2 { stroke: #000; }
.cls-3 {
fill: grey;
stroke: grey;
}
.cls-4 {
fill: #999;
stroke: #999;
}
.tint {
// stroke: purple;
}
.trans { opacity: 0; }
#plane { opacity: 0; }
// .the_worker_head { opacity: 0; }
// ---------------
// SETUP
// ---------------
// var state = 'working';
var controls = document.querySelectorAll("input[type=radio]");
var worker = {
head: document.querySelector('.the_worker_head'),
// at desk
torso: document.querySelector('.the_worker_torso'),
spine: document.querySelector('.spine'),
leftarm: document.querySelector('.leftarm'),
rightarmgroup: document.querySelector('.rightarm'),
rightarm: document.querySelector('.rightarm .arm'),
rightarmmouse: document.querySelector('.rightarm .mouse'),
lowerlegs: document.querySelectorAll('.lowerlegs'),
upperlegs: document.querySelectorAll('.upperlegs'),
rightleg: document.querySelector('.rightlowerleg'),
rightupperleg: document.querySelector('.rightupperleg'),
leftleg: document.querySelector('.leftlowerleg'),
leftupperleg: document.querySelector('.leftupperleg'),
// masking elements
chair: document.querySelectorAll('.chair'),
// transition tail
trail: document.querySelectorAll('.trans'),
trailmain: document.querySelector('.trans_trail'),
trailghost: document.querySelector('.trans_ghost')
}
var lt = function(label, time) {
var tweakedlabel = (time>0) ? (label+'+='+time) : (label+'-='+time);
return tweakedlabel;
}
var master = new TimelineMax({
paused:true
});
master.add(workerCreation(), 'creation' )
// .addPause()
// .add(workerSleeping(), 'sleep' )
// .addPause()
.add(workerWorking(), 'working' )
// .addPause()
.add(workerSleeping(), 'sleep' )
.addPause()
.add(workerTransition(), 'transition' )
.addPause()
.add(workerPlane(), 'plane' );
// .addPause();
// ---------------
// CREATION
// ---------------
function workerCreation() {
var tl = new TimelineMax();
var stdDrawObj = {drawSVG:'0', ease: Power1.easeOut};
var pos = 'creation';
tl.from( worker.head,1.5, {opacity:0, scale: 0, transformOrigin: "26% 20%", ease: Elastic.easeOut.config(1, 0.4) },pos )
.from( worker.spine,1, stdDrawObj, lt(pos,0.75) )
.to( worker.leftarm,1, stdDrawObj, lt(pos,0.85) )
.to( worker.rightarm,1, stdDrawObj, lt(pos,0.85) )
.to( worker.upperlegs,1, stdDrawObj, lt(pos,1.75) )
.to( worker.lowerlegs,1, stdDrawObj, lt(pos,1.75) )
// .from( worker.rightarmmouse,1, {opacity:0},'creation+=3' )
.from( worker.chair,1, {opacity:0, x:-120, y: 68, ease: Power3.easeOut}, lt(pos,1.6) );
return tl;
}
// ---------------
// WORKING
// ---------------
function workerWorking() {
var tl = new TimelineMax();
var pos = 'working';
// Torso
tl.to( worker.torso, 4, { rotation: 3, transformOrigin:"left bottom", repeat:-1, yoyo:true, ease: Power1.easeInOut }, pos )
// right arm
.to( worker.rightarmgroup, 1.5, { rotation: -5, repeat:-1, yoyo:true, ease: Power1.easeInOut }, pos )
// left arm
.to( worker.leftarm, 2, { morphSVG:"M232,213c-4-2,5-3,5-3h23", repeat:-1, yoyo:true, ease: RoughEase.ease.config({
template: Power1.easeInOut, strength: 2, points: 5, taper: "both", randomize: true, clamp: false
}) }, pos )
// right leg
.to( worker.rightleg, 3, { morphSVG:"M226,255l32-5a3,3,0,0,1,3,2l7,21", repeat:-1, yoyo:true, ease: Power2.easeInOut, repeatDelay: 3 }, pos );
return tl;
}
// ---------------
// FALLING ASLEEP
// ---------------
function workerSleeping() {
var tl = new TimelineMax();
var ease = Power1.easeOut;
// go to start position
var pos = 'sleep';
var dur = 1;
tl.to( worker.rightleg, dur, { morphSVG:"M226,255l32-5a3,3,0,0,1,3,3v23", ease:ease}, pos)
.to( worker.leftarm, dur, { morphSVG:"M232,213c-4-2-17,8-17,8l20-11", ease:ease}, pos)
.to( worker.rightarm, dur, { morphSVG:"M232,213c4,2,6,19,6,19a3,3,0,0,0,3,3l26-6", ease:ease}, pos);
// Stretch back
var pos2 = lt(pos,1);
var dur = 1;
tl.to( worker.head, dur, { x:171, y:196, ease:ease}, pos2)
.to( worker.spine, dur, { morphSVG:"M220,259c0-44-5-42-5-52", ease:ease}, pos2)
.to( worker.leftarm, dur, { morphSVG:"M218,220c-4-2-3,1-3,1l20-11", ease:ease}, pos2)
.to( worker.rightarm, dur, { morphSVG:"M218,220l19,13c2,2,3,2,7,2l24-6", ease:ease}, pos2)
.to( worker.leftleg, dur, { morphSVG:"M220,259l10-15a2,2,0,0,1,4,1l3,17", ease:ease}, pos2)
.to( worker.leftupperleg, dur, { morphSVG:"M220,259L231,244", ease:ease}, pos2)
.to( worker.rightleg, dur, { morphSVG:"M220,259l32-5a3,3,0,0,1,3,2l7,21", ease:ease}, pos2)
.to( worker.rightupperleg, dur, { morphSVG:"M220,259l32-5", ease:ease}, pos2)
.to(worker.chair, dur,{x:-10, y: 4, ease:ease}, pos2);
// lie down
var pos3 = lt(pos,2);
var dur = 2;
tl.to( worker.head, dur, { bezier: {type: 'soft',values:[{x:185,y:190},{x:195,y:192},{x:199,y:199}]},ease:ease }, pos3)
.to( worker.leftarm, dur, { morphSVG:"M231,221c-3-2-2-9-1-13a2,2,0,0,1,3-1l21,9", ease:ease}, pos3)
.to( worker.rightarm, dur, { morphSVG:"M231,221c7,4,28,4,28,4s7-2,5-4l-14-14", ease:ease}, pos3)
.to( worker.spine, dur, { morphSVG:"M244,210c-9,6-23,18-23,49", ease:ease}, pos3);
return tl;
}
// ---------------
// TRANSITION
// ---------------
function workerTransition() {
var tl = new TimelineMax();
var ease = Power1.easeOut;
// Fold up
var pos = 'transition';
var dur = 1;
var stdDrawObj = {drawSVG:'0%', ease: Power1.easeOut};
tl.to( worker.lowerlegs, dur, stdDrawObj, pos)
.to( worker.upperlegs, 0.5, stdDrawObj, lt(pos,0.5) )
.to( worker.spine, dur, stdDrawObj, lt(pos,1) )
.to( worker.leftarm, dur, stdDrawObj, lt(pos,0.5) )
.to( worker.rightarm, dur, stdDrawObj, lt(pos,0.5) )
.to( worker.head,1.25, {scale: 0.75, transformOrigin: "26% 20%", ease: Power2.easeOut }, lt(pos,1.4) );
// tadpole mode
var pos2 = lt(pos,2);
tl.from( worker.trail,1.5,{ scaleY:0, transformOrigin: "center top", ease:ease },pos2)
.to( worker.trailmain,1,{ opacity:1, ease:ease },pos2)
.to( worker.trailghost,1,{ opacity:0.3, ease:ease },pos2);
// tadpole reposition
var pos3 = lt(pos,2.75);
var elasticEase = Elastic.easeOut.config(1, 0.4);
tl.to( worker.head,1.25, { rotation:-25, ease: Power2.easeIn }, pos3 )
.to( worker.head,2.5, { bezier: {type: 'soft',values:[{x:195,y:190},{x:175,y:180},{x:170,y:170}]}, ease: Power1.easeInOut }, pos3 )
.to( worker.head,1.25, { rotation:0, ease: Power2.easeOut }, lt(pos,4) );
return tl;
}
// ---------------
// INTO PLANE
// ---------------
function workerPlane() {
var tl = new TimelineMax();
var ease = Power1.easeOut;
// retract tadpole & resize head
var pos = 'plane';
tl.to( worker.trail,1.5, { scaleY:0, transformOrigin: "center top", ease:ease },pos)
.to( worker.head,1.25, { scale: 1, transformOrigin: "26% 20%", ease:ease }, lt(pos,0.4) );
return tl;
}
// ---------------
// FLYING
// ---------------
// ------------
for (var i = 0; i < controls.length; i++) {
controls[i].addEventListener("change", function(){
// state = this.value;
// console.log(state);
master.kill().seek(this.value).play();
}, 0);
}
Also see: Tab Triggers