Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

Save Automatically?

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 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>
              
            
!

CSS

              
                // 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; }
              
            
!

JS

              
                // ---------------
// 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);
}
              
            
!
999px

Console