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

              
                <!-- We can create one master SVG element to hold all shared defs -->
<svg viewBox="0 0 84 176">
	<defs>
		<linearGradient id="grad" x1="0" x2="0", y1="0" y2="1">
			<stop offset="0%" stop-color="#252017" />
			<stop offset="100%" stop-color="#4b3d2d" />
		</linearGradient>
	</defs>
</svg><!-- Defs SVG -->


<div class="container triplempu">

	<div id="hero">

	<div id="capeLeft">
		<svg id="clothLeft" viewBox="0 0 50 160">
			<path id="clothLeftP" fill="url(#grad)" d="M0 0 L25 0 Q50 120, 32 160 Q10 150, 0 150 Z" />
		</svg>

		<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_cape_Left_double.png" />
	</div>

	<div id="capeRight">
		<svg id="clothRight" viewBox="0 0 50 160">
			<path id="clothRightP" fill="url(#grad)" d="M50 0 L50 150 Q40 150, 18 160 Q0 120, 25 0 Z" />
		</svg>

		<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_cape_Right_double.png" />
	</div>


	<img id="armLeft" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_arm_Left_double.png" />
	<img id="armRight" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_arm_Right_double.png" />
	<img id="body" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_body_double.png" />
	</div><!-- #hero -->
	
</div><!-- .container .triplempu -->



<div class="container doublempu">

	<div id="hero">

	<div id="capeLeft">
		<svg id="clothLeft" viewBox="0 0 50 160">
			<path id="clothLeftP" fill="url(#grad)" d="M0 0 L25 0 Q50 120, 32 160 Q10 150, 0 150 Z" />
		</svg>

		<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_cape_Left.png" />
	</div>

	<div id="capeRight">
		<svg id="clothRight" viewBox="0 0 50 160">
			<path id="clothRightP" fill="url(#grad)" d="M50 0 L50 150 Q40 150, 18 160 Q0 120, 25 0 Z" />
		</svg>

		<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_cape_Right.png" />
	</div>


	<img id="armLeft" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_arm_Left.png" />
	<img id="armRight" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_arm_Right.png" />
	<img id="body" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_body.png" />
	</div><!-- #hero -->
	
</div><!-- .container .doublempu -->



<div class="container mpu">

	<div id="hero">

	<div id="capeLeft">
		<svg id="clothLeft" viewBox="0 0 50 160">
			<path id="clothLeftP" fill="url(#grad)" d="M0 0 L25 0 Q50 120, 32 160 Q10 150, 0 150 Z" />
		</svg>
	
		<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_cape_Left_half.png" />
	</div>

	<div id="capeRight">
		<svg id="clothRight" viewBox="0 0 50 160">
			<path id="clothRightP" fill="url(#grad)" d="M50 0 L50 150 Q40 150, 18 160 Q0 120, 25 0 Z" />
		</svg>
	
		<img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_cape_Right_half.png" />
	</div>


	<img id="armLeft" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_arm_Left_half.png" />
	<img id="armRight" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_arm_Right_half.png" />
	<img id="body" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/259155/hero_body_half.png" />
	</div><!-- #hero -->

</div><!-- .container .mpu -->

              
            
!

CSS

              
                .container {
	border: 1px solid black;
	position: relative;
	overflow: hidden;
	margin: 10px;
	float: left;
}

.mpu {
	width: 300px;
	height: 250px;	
}

.doublempu {
	width: 300px;
	height: 600px;
}

.triplempu {
	width: 300px;
	height: 880px;
}

img, div, svg {
	position: absolute;
}


svg {
	height: 100%;
	width: 150%;
	top: 0;
	overflow: visible;
}


#hero {
	left: 50%;
	top: 50%;
	transform:translate(-50%, -50%);

	#body {
		position: relative;
	}

	#armLeft,
	#armRight {
		top: 18%
	}

	#armLeft {
		left: 86%;
	}

	#armRight {
		left: -56%;
	}

	#capeLeft,
	#capeRight {
		top: 20%;

		img {
			position: relative;
		}
	}

	#capeLeft {
		left: 76%;

		svg {
			right: 0;
		}
	}

	#capeRight {
		left: -24%;

		svg {
			left: 0;
		}
	}
}
              
            
!

JS

              
                // wait until DOM is ready
document.addEventListener("DOMContentLoaded", function(event) {
	// wait until window, stylesheets, images, links, and other media assets are loaded
	window.onload = function() {
		
		var main_tl = new TimelineLite( {onComplete:loop} ),
			dur = 0.3,
			hold = 1,
			h = -250;
		

		main_tl
			.add('heroIn')
			.from(hero, dur*5, {yPercent:h, ease: Back.easeOut.config(0.85)}, "heroIn")
			.add(limbIn(armLeft, "left", 15), "heroIn+=0.1")
			.add(limbIn(armRight, "right", 15), "heroIn+=0.1")
			.add('cape', "heroIn")
			.add(limbIn(capeLeft, "left"), "cape")
			.add(capeDeform('clothLeftP', "M0 0 L25 0 Q50 120, 32 160 Q10 100, -40 100 Z"), "cape")
			.add(limbIn(capeRight, "right"), "cape")
			.add(capeDeform('clothRightP', "M50 0 L90 100 Q40 100, 18 160 Q0 120, 25 0 Z"), "cape")

		// Wait a little
			.add("heroOut", "+="+hold)
			.add(limbOut(armLeft, "left", 25, dur*1.5), "heroOut")
			.add(limbOut(armRight, "right", 25, dur*1.5), "heroOut")
			.to(hero, dur*3, {yPercent:h, ease:Back.easeIn.config(2.5)}, "heroOut+=0.15")
			.add(limbOut(capeLeft, "left", 10, dur*1.5), "heroOut+=0.2")
			.add(capeDeform('clothLeftP', "M0 0 L25 0 Q50 120, 32 160 Q10 150, -20 150 Z", dur), "heroOut+=0.2")
			.add(limbOut(capeRight, "right", 10, dur*1.5), "heroOut+=0.2")
			.add(capeDeform('clothRightP', "M50 0 L70 150 Q40 150, 18 160 Q0 120, 25 0 Z", dur), "heroOut+=0.2");



		function loop() {
			TweenMax.delayedCall(1, function() { main_tl.play(0); } );
		}


		function limbIn (target, side, amount, dur) {
				var tl = new TimelineLite();
				var amount = amount || 20;
				var dur = dur || 1;

				var orientation = checkSide(side);

				tl.add("start")
						.to(target, dur, {rotation:"+="+(orientation[0]*amount), transformOrigin:orientation[1], ease:Power1.easeOut}, "start")
						.to(target, dur*0.35, {rotation:"-="+(orientation[0]*(amount*0.5)), transformOrigin:orientation[1], ease:Power1.easeIn})
						.to(target, dur, {rotation:0, transformOrigin:orientation[1], ease:Back.easeOut.config(4)})

				return tl;
		}


		function limbOut(target, side, amount, dur) {
				var tl = new TimelineLite();
				var amount = amount || 20;
				var dur = dur || 1;

				var orientation = checkSide(side)

				tl.add("start")
						.to(target, dur, {rotation:"+="+(orientation[0]*amount), transformOrigin:orientation[1], ease:Power1.easeInOut})
						.to(target, dur*2, {rotation:"-="+(orientation[0]*amount), transformOrigin:orientation[1], ease:Back.easeOut.config(5)})

				return tl;
		}



		function checkSide(side) {
				var dir, origin;

				if(side === "left") {
						dir = -1;
						origin = "15% 5%";
				} else {
						dir = 1;
						origin = "75% 5%";
				}

				return [dir, origin];
		}



		/* *********
				Credit where credit is due:
				capeDeform(), update() and parsePath()
				originally by BlakeBowen
				https://codepen.io/osublake/pen/RPKdQz
				
				I modified Blake's original code so it would work in this example. I needed to be able to have it affect several different elements with the same id to illustrate my point in the blog post.
		************* */
		function capeDeform(element, path, dur) {
				var dur = dur || 1;

			var cloth = document.getElementById(element);
				var path1 = cloth.getAttribute("d"); // The original path
				var path2 = path; // The new path to deform into
				var path3 = path1 // The original path - to deform back into original shape

				path1 = parsePath(path1);
				path2 = parsePath(path2);
				path3 = parsePath(path3);

				var tl = new TimelineLite();

				tl.to(path1, dur, { endArray: path2, onUpdate: update, onUpdateParams: [element, path1], ease:Power1.easeOut })
						.to(path2, dur, { endArray: path3, onUpdate: update, onUpdateParams: [element, path2] }, "+=0.1")

				return tl;
		}

		function update(element, path) {
			TweenMax.set("#"+element, {attr:{d:path.string()}})
		}

		function parsePath(string) {

				// Split the string into path commands and points
				var pathExp = /[achlmrqstvz]|(-?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig;
				var path = string.match(pathExp).map(function(n) { return isNaN(+n) ? n : +n; });

				// The first element needs to be a number, so remove if it's not
				// Calling the string method will return the path with the removed element
				path.prefix = isNaN(path[0]) ? path.shift() : "";
				path.string = function() { return path.prefix + path.join(" "); };

				return path;
		}
	}
});
              
            
!
999px

Console