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="minifigure">
<div class="head">
<div class="faces-wrap">
<div class="faces">
<div class="face classic">
<div class="eye right"></div>
<div class="eye left"></div>
<div class="mouth"></div>
</div>
<div class="face smile">
<div class="eye right">
<div class="brow"></div>
</div>
<div class="eye left">
<div class="brow"></div>
</div>
<div class="mouth"></div>
</div>
<div class="face large-smile">
<div class="eye right">
<div class="brow"></div>
</div>
<div class="eye left">
<div class="brow"></div>
</div>
<div class="mouth"></div>
</div>
<div class="face worried">
<div class="eye right">
<div class="brow"></div>
</div>
<div class="eye left">
<div class="brow"></div>
</div>
<div class="mouth"></div>
</div>
<div class="face frown">
<div class="eye right">
<div class="brow"></div>
</div>
<div class="eye left">
<div class="brow"></div>
</div>
<div class="mouth"></div>
</div>
<div class="face surprised">
<div class="eye right">
<div class="brow"></div>
</div>
<div class="eye left">
<div class="brow"></div>
</div>
<div class="mouth"></div>
</div>
</div>
</div>
</div>
<div class="upper-body">
<div class="torso"></div>
<div class="arm right">
<div class="hand right"></div>
</div>
<div class="arm left">
<div class="hand left"></div>
</div>
</div>
<div class="lower-body">
<div class="waist"></div>
<div class="crotch"></div>
<div class="leg right"></div>
<div class="leg left"></div>
</div>
</div>
<div class="controls">
<h2 class="title">Controls</h2>
<button class="button explode">Explode</button>
<button class="button randomize">Randomize</button>
<fieldset class="head-expression">
<legend>Head</legend>
<div class="form-element">
<label for="expression">Expression</label>
<input id="expression" class="expression-range expression" name="expression" type="range" min="0" max="500" step="100" value="0">
</div>
</fieldset>
<fieldset class="upper-color">
<legend>Upper Body</legend>
<div class="form-element">
<label for="upper-hue">Hue</label>
<input id="upper-hue" class="color-range upper-hue" name="upper-hue" type="range" min="0" max="360" value="200">
</div>
<div class="form-element">
<label for="upper-saturation">Saturation</label>
<input id="upper-saturation" class="color-range upper-saturation" name="upper-saturation" type="range" min="0" max="100" value="0">
</div>
<div class="form-element">
<label for="upper-lightness">Lightness</label>
<input id="upper-lightness" class="color-range upper-lightness" name="upper-lightness" type="range" min="0" max="90" value="90">
</div>
</fieldset>
<fieldset class="lower-color">
<legend>Lower Body</legend>
<div class="form-element">
<label for="lower-hue">Hue</label>
<input id="lower-hue" class="color-range lower-hue" name="lower-hue" type="range" min="0" max="360" value="200">
</div>
<div class="form-element">
<label for="lower-saturation">Saturation</label>
<input id="lower-saturation" class="color-range lower-saturation" name="lower-saturation" type="range" min="0" max="100" value="0">
</div>
<div class="form-element">
<label for="lower-lightness">Lightness</label>
<input id="lower-lightness" class="color-range lower-lightness" name="lower-lightness" type="range" min="0" max="90" value="90">
</div>
</fieldset>
</div>
html {
box-sizing: border-box;
}
*,
*::before,
*::after {
box-sizing: inherit;
padding: 0;
margin: 0;
}
body {
display: flex;
height: 100vh;
font-family: Montserrat, sans-serif;
}
.minifigure {
position: relative;
width: 300px;
height: 485px;
margin: auto;
perspective: 200;
transform-style: preserve-3d;
transition: transform 400ms;
}
.minifigure.explode {
transform: scale(0.75) translateZ(0);
}
/* Head */
.head {
position: absolute;
z-index: 2;
top: 2.25em;
left: 50%;
width: 7.25em;
height: 6.25em;
transform: translateX(-50%);
color: hsla(50,90%,50%,1);
background-color: currentColor;
background-image:
linear-gradient(
rgba(255,255,255,0.3),
rgba(255,255,255,0) 20%,
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.15) 95%,
rgba(0,0,0,0.3)
),
linear-gradient(
to right,
rgba(255,255,255,0) 50%,
rgba(255,255,255,0.2),
rgba(255,255,255,0)
);
border-radius: 1.5em;
transition: transform 400ms;
}
.explode .head {
transform: translate(-50%, -8em);
}
.head::before,
.head::after {
content: '';
position: absolute;
left: 50%;
height: 2em;
transform: translateX(-50%);
background-color: currentColor;
}
.head::before {
top: -1.25em;
width: 3.5em;
height: 1.25em;
background-image:
linear-gradient(
rgba(255,255,255,0.5),
rgba(255,255,255,0) 30%
),
linear-gradient(
to right,
rgba(255,255,255,0) 70%,
rgba(255,255,255,0.25) 80%,
rgba(255,255,255,0) 90%
);
border-radius: 0.25em 0.25em 0 0;
}
.head::after {
bottom: -0.875em;
width: 4.5em;
height: 1em;
background-image:
linear-gradient(
rgba(0,0,0,0.2),
rgba(0,0,0,0.05) 50%
),
linear-gradient(
to right,
rgba(255,255,255,0) 70%,
rgba(255,255,255,0.25) 80%,
rgba(255,255,255,0) 90%
);
border-radius: 0 0 0.125em 0.125em;
}
/* Faces */
.faces-wrap {
height: 100%;
overflow: hidden;
}
.faces {
display: flex;
transition: transform 400ms cubic-bezier(0,0,0,1.25);
}
.explode .faces {
transform: translateX(-500%) !important;
}
.face {
position: relative;
flex: 1 0 100%;
}
/* Eyes */
.eye {
position: absolute;
top: 2.25em;
width: 0.75em;
height: 0.9375em;
color: #fff;
background-color: currentColor;
border-radius: 50%;
box-shadow: inset 0 -0.125em 0 0.25em #000;
}
.eye::before {
content: '';
position: absolute;
left: 50%;
color: #000;
transform: translateX(-50%);
}
.eye.right {
left: 2.25em;
}
.eye.left {
right: 2.25em;
}
.classic .eye {
top: 2.4375em;
height: 0.75em;
color: #000;
box-shadow: none;
}
.large-smile .eye {
top: 2em;
}
.worried .eye,
.surprised .eye {
top: 2.4375em;
width: 1em;
height: 1.125em;
box-shadow: inset 0 -0.125em 0 0.3125em #000;
}
.worried .eye.right {
left: 2.125em;
}
.worried .eye.left {
right: 2.125em;
}
.frown .eye {
top: 2.625em;
}
.frown .eye::before {
bottom: 80%;
width: 1.25em;
height: 1em;
border: 0.1875em solid transparent;
border-bottom-color: currentColor;
border-radius: 50%;
}
.frown .eye.right::before {
margin-left: -0.25em;
transform: translateX(-50%) rotate(-20deg);
}
.frown .eye.left::before {
margin-left: 0.25em;
transform: translateX(-50%) rotate(20deg);
}
/* Brow */
.brow {
position: absolute;
bottom: 0.625em;
left: 50%;
width: 1.75em;
height: 1em;
transform-origin: 0 0;
transform: translateX(-50%);
color: #000;
border: 0.25em solid transparent;
border-top-color: currentColor;
border-bottom: none;
border-radius: 50% 50% 0 0;
}
.right .brow {
border-left: none;
}
.left .brow {
border-right: none;
}
.large-smile .brow {
bottom: 0.375em;
width: 1.25em;
height: 1.375em;
border: none;
border-top: 0.25em solid;
border-radius: 50% 50% 0 0;
}
.large-smile .right .brow {
margin-left: -0.125em;
transform: skewY(-10deg) translateX(-50%) translateZ(0);
}
.large-smile .left .brow {
margin-left: 0.125em;
transform: skewY(10deg) translateX(-50%) translateZ(0);
}
.worried .brow {
width: 1.25em;
height: 0.875em;
bottom: 1.25em;
border-top: none;
border-bottom: 0.25em solid currentColor;
border-radius: 0 0 50% 50%;
}
.worried .right .brow {
margin-left: -0.25em;
transform: rotate(-20deg) translateX(-50%) translateZ(0);
}
.worried .left .brow {
margin-left: 0.25em;
transform: rotate(20deg) translateX(-50%) translateZ(0);
}
.frown .brow {
width: 1.5em;
bottom: 1.375em;
border-top: none;
border-bottom: 0.25em solid currentColor;
border-radius: 0 0 50% 50%;
}
.frown .right .brow {
margin-left: -0.625em;
transform: rotate(-35deg) translateX(-50%) translateZ(0);
}
.frown .left .brow {
margin-left: 0.625em;
transform: rotate(35deg) translateX(-50%) translateZ(0);
}
.surprised .brow {
bottom: 1em;
width: 1.5em;
border-right: none;
border-left: none;
}
.surprised .right .brow {
margin-left: -0.5em;
transform: rotate(-15deg) translateX(-50%) translateZ(0);
}
.surprised .left .brow {
margin-left: 0.5em;
transform: rotate(15deg) translateX(-50%) translateZ(0);
}
/* Mouth */
.mouth {
position: absolute;
top: 3.125em;
left: 50%;
width: 2.5em;
height: 1.5em;
transform: translateX(-50%);
color: #000;
border: 0.25em solid transparent;
border-bottom-color: currentColor;
border-radius: 50%;
}
.mouth::before,
.mouth::after {
content: '';
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.classic .mouth {
top: 2.9375em;
}
.large-smile .mouth {
top: 0.125em;
width: 3.125em;
height: 5em;
border: none;
border-bottom: 1.5em solid;
border-radius: 0 0 70% 70%/0 0 50% 50%;
}
.large-smile .mouth::before {
top: 1.6875em;
width: 4.25em;
height: 2em;
color: #000;
border: 0.1875em solid transparent;
border-bottom-color: currentColor;
border-radius: 0 0 50% 50%;
box-shadow: 0 0.9375em 0 -0.75em #fff;
}
.large-smile .mouth::after {
top: 4.4375em;
width: 1.25em;
height: 0.375em;
color: #c00;
background-color: currentColor;
border-radius: 70% 70% 70% 70%/50% 50% 100% 100%;
}
.worried .mouth {
top: 4.5em;
width: 2em;
height: 1.25em;
transform: translateX(-50%) rotate(-10deg) translateZ(0);
border-top-color: currentColor;
border-right: none;
border-bottom-color: transparent;
border-right-width: 0.5em;
border-radius: 50% 50% 0 0;
}
.frown .mouth {
top: 4.25em;
width: 2.75em;
height: 2em;
margin-left: -0.125em;
transform: translateX(-50%) rotate(-15deg) translateZ(0);
border-top-color: currentColor;
border-right: none;
border-bottom-color: transparent;
border-right-width: 0.5em;
border-radius: 50% 50% 0 0;
}
.frown .mouth::before {
top: 0.375em;
width: 0.75em;
height: 0.625em;
margin-left: 0.125em;
color: #000;
border: 0.125em solid transparent;
border-top-color: currentColor;
border-right: none;
border-radius: 50%;
border-radius: 50% 50% 0 0;
}
.surprised .mouth {
top: 4em;
width: 3.125em;
height: 1.625em;
background-color: currentColor;
border: none;
border-radius: 70% 70% 60% 60%/100% 100% 50% 50%;
}
.surprised .mouth::before,
.surprised .mouth::after {
color: #fff;
background-color: currentColor;
}
.surprised .mouth::before {
top: 0.1875em;
width: 2em;
height: 0.375em;
border-radius: 70% 70% 60% 60%/100% 100% 50% 50%;
}
.surprised .mouth::after {
bottom: 0.1875em;
width: 2.25em;
height: 0.375em;
border-radius: 70% 70% 60% 60%/100% 100% 50% 50%;
}
/* Upper Body */
.upper-body {
position: absolute;
z-index: 1;
top: 9.25em;
width: 100%;
color: hsl(200,0%,90%);
perspective: 320px;
}
.upper-body::before,
.upper-body::after {
content: '';
position: absolute;
left: 50%;
transform: translateX(-50%);
}
.upper-body::before {
bottom: 100%;
width: 3em;
height: 3.5em;
background-color: currentColor;
background-image:
linear-gradient(
to right,
rgba(255,255,255,0) 50%,
rgba(255,255,255,0.2),
rgba(255,255,255,0) 90%
),
linear-gradient(
rgba(0,0,0,0) 50%,
rgba(0,0,0,0.05) 80%,
rgba(0,0,0,0.1)
);
border-radius: 50% 50% 0 0/10% 10% 0 0;
}
.upper-body::after {
top: -2.75em;
width: 2em;
height: 2em;
background-color: rgba(0,0,0,0.9);
background-image:
linear-gradient(
to right,
rgba(255,255,255,0) 50%,
rgba(255,255,255,0.2) 80%,
rgba(255,255,255,0)
);
border-radius: 50%/10%;
}
.torso {
position: absolute;
z-index: 1;
top: 0;
left: 50%;
width: 7.75em;
height: 9.125em;
transform-origin: top center;
transform: translateX(-50%) rotateX(45deg);
background-color: currentColor;
background-image:
linear-gradient(
rgba(255,255,255,0.1),
rgba(0,0,0,0) 80%,
rgba(0,0,0,0.05) 98%,
rgba(0,0,0,0.25) 100%
);
border-radius: 0.5em 0.5em 0.125em 0.125em;
box-shadow:
inset 0 0.25em 0.25em rgba(255,255,255,0.5),
-1.5em 0.5em 1em -1.25em rgba(0,0,0,0.3),
1.5em 0.5em 1em -1.25em rgba(0,0,0,0.3);
}
.arm {
position: absolute;
left: 50%;
top: 4em;
width: 3em;
height: 5.5em;
transform-origin: center 1.5em;
background-color: currentColor;
border-radius: 1.5em/1em;
}
.arm.right {
margin-left: -6.25rem;
transform: translateX(-50%) rotate(12deg);
box-shadow:
inset 0.5em 0.25em 0.375em -0.25em rgba(255,255,255,0.4),
inset 0 0 0.75em 0.75em currentColor,
inset 0 0 0 2em rgba(255,255,255, 0.15);
}
.arm.left {
margin-left: 6.25rem;
transform: translateX(-50%) rotate(-12deg);
box-shadow:
inset -0.5em 0.25em 0.375em -0.25em rgba(255,255,255,0.4),
inset 0 0 0.75em 0.75em currentColor,
inset 0 0 0 2em rgba(255,255,255, 0.15);
}
.arm::before {
content: '';
position: absolute;
bottom: 3.5em;
left: 0;
width: 100%;
height: 5.5em;
backface-visibility: hidden;
transform-origin: center 4.5em;
background-color: currentColor;
border-radius: 1.5em/1.5em 1.5em 1em 1em;
}
.arm.right::before {
transform: rotate(14deg);
box-shadow:
inset 0.75em 0.125em 0.375em -0.5em rgba(255,255,255,0.4),
inset 0.25em 1.1em 0.75em 0.75em currentColor,
inset 0 0 0 2em rgba(255,255,255, 0.15);
}
.arm.left::before {
transform: rotate(-14deg);
box-shadow:
inset -0.75em 0.125em 0.375em -0.5em rgba(255,255,255,0.4),
inset -0.25em 1.1em 0.75em 0.75em currentColor,
inset 0 0 0 2em rgba(255,255,255, 0.15);
}
.arm::after {
content: '';
position: absolute;
bottom: 0;
left: 0;
width: 100%;
height: 1.5em;
transform-origin: center 4.5em;
background-color: currentColor;
border-radius: 50%;
box-shadow: inset 0 0 0 1em rgba(255,255,255,0.2);
}
.hand {
position: absolute;
z-index: 1;
top: 80%;
left: 50%;
width: 1.75em;
height: 1.75em;
transform: translateX(-50%);
color: hsla(50,90%,50%,1);
background-color: currentColor;
background-image:
linear-gradient(
to right,
rgba(255,255,255,0.2),
rgba(0,0,0,0.075),
rgba(255,255,255,0.2)
);
border-radius: 1em/0.5em;
box-shadow: 0 -0.125em 0.125em rgba(0,0,0,0.1);
}
.hand::before {
content: '';
position: absolute;
z-index: 1;
top: 1em;
left: 50%;
width: 3.5em;
height: 3.5em;
transform: translateX(-50%);
color: hsla(50,90%,60%,1);
border: 0.75em solid;
border-bottom-color: transparent;
box-shadow:
inset 0 0.25em rgba(0,0,0,0.15),
inset 0 0.25em;
border-radius: 50%;
}
/* Lower Body */
.lower-body {
position: absolute;
top: 18.5em;
left: 50%;
width: 10em;
height: 11.75em;
transform: translateX(-50%);
color: hsl(200,0%,90%);
transition: transform 400ms;
}
.explode .lower-body {
transform: translate(-50%, 8em);
}
.lower-body > div {
position: absolute;
background-color: currentColor;
}
.waist {
z-index: 1;
top: 0;
width: 100%;
height: 1.5em;
background-image:
linear-gradient(
rgba(0,0,0,0.15),
rgba(0,0,0,0) 80%,
rgba(255,255,255,0.1) 90%,
rgba(255,255,255,0.15)
);
border-radius: 0.125em;
box-shadow: 0 0.75em 0.75em -0.25em rgba(0,0,0,0.25);
}
.waist::before,
.waist::after {
content: '';
position: absolute;
bottom: 100%;
left: 50%;
width: 3em;
height: 3em;
transform: translateX(-50%);
background-color: currentColor;
background-image:
linear-gradient(
rgba(255,255,255,0.75),
rgba(255,255,255,0) 10%
),
linear-gradient(
to right,
rgba(255,255,255,0) 20%,
rgba(255,255,255,0.25) 25%,
rgba(255,255,255,0) 40%,
rgba(255,255,255,0) 60%,
rgba(255,255,255,0.25) 75%,
rgba(255,255,255,0) 80%,
rgba(255,255,255,0.2)
),
linear-gradient(
rgba(255,255,255,0.1),
rgba(0,0,0,0.15)
);
}
.waist::before {
margin-left: -2.75em;
border-radius: 50% 30% 0 0/100% 30% 0 100%;
}
.waist::after {
margin-left: 2.75em;
border-radius: 30% 50% 0% 0%/30% 100% 100% 0%;
}
.crotch {
z-index: 1;
top: 1.5em;
left: 50%;
width: 10%;
height: 4.5em;
transform: translateX(-50%);
background-image:
linear-gradient(
rgba(0,0,0,0.2),
rgba(0,0,0,0.05) 10%,
rgba(0,0,0,0.2) 10%,
rgba(255,255,255,0.1),
rgba(0,0,0,0.1)
);
border-radius: 0 0 0.25em 0.25em;
box-shadow:
-0.5em 0 0.25em -0.25em rgba(0,0,0,0.15),
0.5em 0 0.25em -0.25em rgba(0,0,0,0.15),
-0.25em 0 0.125em -0.125em rgba(0,0,0,0.2),
0.25em 0 0.125em -0.125em rgba(0,0,0,0.2);
}
.leg {
bottom: 0;
left: 50%;
width: 4.75em;
height: 10.75em;
transform: translateX(-50%);
background-image:
linear-gradient(
rgba(0,0,0,0.1) 10%,
rgba(255,255,255,0.1) 25%,
rgba(0,0,0,0.1) 45%,
rgba(0,0,0,0), 50%,
rgba(0,0,0,0.05), 65%,
rgba(0,0,0,0) 74%,
rgba(0,0,0,0.1), 78%,
rgba(255,255,255,0.2) 78%,
rgba(255,255,255,0) 82%,
rgba(0,0,0,0.1)
);
border-radius: 0.25em 0.25em 0.0625em 0.0625em;
}
.leg.right {
margin-left: -2.75em;
}
.leg.left {
margin-left: 2.75em;
}
/* Controls */
.controls {
position: relative;
z-index: 1;
width: 200px;
padding: 1.5em;
color: #333;
text-transform: uppercase;
background-color: rgba(220,220,220,0.5);
}
.controls .title {
margin-bottom: 0.5rem;
font-weight: 900;
font-size: 1.25em;
letter-spacing: 0.03125em;
}
.button {
width: 100%;
padding: 0.5em 1em;
margin: 0.25rem 0;
color: #666;
font-family: inherit;
text-transform: uppercase;
letter-spacing: 0.0625em;
background-color: #fff;
border: 1px solid #ddd;
border-radius: 0.5em;
cursor: pointer;
outline: none;
}
.button:hover {
color: #000;
border-color: #ccc;
}
.button:active {
background-color: #ddd;
}
.controls fieldset {
border: none;
margin: 1rem 0;
}
.controls legend {
margin-bottom: 1rem;
font-weight: bold;
font-size: small;
letter-spacing: 0.03125em;
}
.controls label {
display: block;
font-size: x-small;
letter-spacing: 0.0625em;
}
.controls input[type="range"] {
-webkit-appearance: none;
appearance: none;
position: relative;
width: 100%;
height: 2em;
padding: 0.375em;
margin: 0.25rem 0 1rem;
color: inherit;
background-color: currentColor;
border-radius: 1em;
outline: none;
}
.controls input[type="range"]::-webkit-slider-thumb {
-webkit-appearance: none;
appearance: none;
position: relative;
z-index: 10;
width: 1.5em;
height: 1.5em;
background-color: hsla(50,90%,50%,1);
border-radius: 50%;
cursor: pointer;
}
.controls input[type="range"]::-moz-range-thumb {
position: relative;
z-index: 10;
width: 1.5em;
height: 1.5em;
background-color: #333;
border-radius: 50%;
cursor: pointer;
}
.controls input[type="range"]::-moz-range-track {
background-color: transparent;
}
var minifigure = document.querySelector('.minifigure');
var faces = document.querySelector('.faces');
var upperBody = document.querySelector('.upper-body');
var lowerBody = document.querySelector('.lower-body');
var explode = document.querySelector('.explode');
var randomize = document.querySelector('.randomize');
var expressionRangeInput = document.querySelector('.expression-range');
var colorRangeInput = document.querySelectorAll('.color-range');
var upperHue = document.getElementById('upper-hue');
var upperSaturation = document.getElementById('upper-saturation');
var upperLightness = document.getElementById('upper-lightness');
var lowerHue = document.getElementById('lower-hue');
var lowerSaturation = document.getElementById('lower-saturation');
var lowerLightness = document.getElementById('lower-lightness');
explode.addEventListener('click', explodeMinifigure);
randomize.addEventListener('click', randomizeInputs);
expressionRangeInput.addEventListener('input', setExpression);
for (var i = 0; i < colorRangeInput.length; i++) {
colorRangeInput[i].addEventListener('input', setColors);
}
function getRandomNum(min, max) {
return Math.random() * (max - min) + min;
}
function explodeMinifigure() {
minifigure.classList.toggle('explode');
if (minifigure.classList.contains('explode')) {
explode.innerHTML = 'Rebuild';
} else {
explode.innerHTML = 'Explode';
}
};
function randomizeInputs() {
var randomExpression = getRandomNum(0, 5);
var randomUpperHue = getRandomNum(0, 360);
var randomUpperSaturation = getRandomNum(0, 100);
var randomUpperLightness = getRandomNum(0, 90);
var randomLowerHue = getRandomNum(0, 360);
var randomLowerSaturation = getRandomNum(0, 100);
var randomLowerLightness = getRandomNum(0, 90);
expressionRangeInput.value = randomExpression * 100;
upperHue.value = randomUpperHue;
upperSaturation.value = randomUpperSaturation;
upperLightness.value = randomUpperLightness;
lowerHue.value = randomLowerHue;
lowerSaturation.value = randomLowerSaturation;
lowerLightness.value = randomLowerLightness;
setExpression();
setColors();
};
function setExpression() {
var expressionVal = parseInt(expressionRangeInput.value);
faces.style.transform = 'translateX(-' + expressionVal + '%)';
};
function setColors() {
var upperHueVal = parseInt(upperHue.value);
var upperSaturationVal = parseInt(upperSaturation.value);
var upperLightnessVal = parseInt(upperLightness.value);
var lowerHueVal = parseInt(lowerHue.value);
var lowerSaturationVal = parseInt(lowerSaturation.value);
var lowerLightnessVal = parseInt(lowerLightness.value);
upperBody.style.color = 'hsl(' + upperHueVal + ',' + upperSaturationVal + '%,' + upperLightnessVal + '%)';
lowerBody.style.color = 'hsl(' + lowerHueVal + ',' + lowerSaturationVal + '%,' + lowerLightnessVal + '%)';
};
Also see: Tab Triggers