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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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="scene">
<div class="panda__wrap"><svg
class='panda'
viewBox="0 0 319.01019 223.16049"
preserveAspectRatio='xMinYMin'>
<g
transform="translate(27.242913,-815.78013)"
id="layer1">
<g
id="g4222">
<path
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 123.47579,99.788805 C 70.999645,100.27156 30.49513,134.00241 20.460938,171.45117 c -0.07341,0.32753 -0.144371,0.65567 -0.212891,0.98438 l 253.980473,68.05468 c 0.11178,-0.31762 0.22116,-0.63598 0.32812,-0.95507 -3.37938,-52.83531 -33.56103,-114.78104 -103.72772,-133.58228 -15.74793,-4.21933 -31.58286,-6.309538 -47.35313,-6.164075 z"
transform="translate(0,752.36216)"
id="path4138" />
<ellipse
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:10;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4149"
cx="359.91046"
cy="868.42615"
rx="16.725821"
ry="8.973033"
transform="matrix(0.96291738,0.26979644,-0.24822638,0.96870205,0,0)" />
<g
id="g4175"
transform="translate(-0.67264574,12.107623)">
<ellipse
transform="matrix(0.96592583,-0.25881905,0.25881905,0.96592583,0,0)"
ry="21.524664"
rx="27.746635"
cy="896.90204"
cx="-139.17584"
id="path4161"
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
r="5"
cy="911.15143"
cx="96.47982"
id="path4167"
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
id="g4171"
transform="translate(15.134529,15.470851)">
<ellipse
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="ellipse4165"
cx="-770.41119"
cy="536.63788"
rx="27.746635"
ry="21.524664"
transform="matrix(-0.70710678,-0.70710678,-0.70710678,0.70710678,0,0)" />
<circle
style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="circle4169"
cx="154.66368"
cy="929.31287"
r="5" />
</g>
<path
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:11.11824894;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 112.08398,815.78013 a 25,25 0 0 0 -24.999996,25 25,25 0 0 0 5.550782,15.69336 c 9.663184,-2.68167 19.991444,-4.22245 30.841794,-4.32227 3.57198,-0.0329 7.14581,0.0548 10.72266,0.25 a 25,25 0 0 0 2.88476,-11.62109 25,25 0 0 0 -25,-25 z"
id="path4145" />
<path
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="m 240.91992,862.11607 a 25,25 0 0 0 -24.01562,18.125 c 12.0605,8.90778 22.04335,19.50643 30.12695,31.09179 a 25,25 0 0 0 18.88867,-24.21679 25,25 0 0 0 -25,-25 z"
id="path4198" />
</g>
<path
id="path4309"
d="M 290.24664,997.54153 -12.399607,916.44772"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
transform="translate(27.242913,-63.41797)"
id="layer2">
<g
id="g4251"
class='panda__paw panda__paw--right'
transform="translate(0,-752.36216)">
<path
id="path4241"
d="m 228.90463,923.66963 a 36.827354,21.356503 79.346212 0 0 -2.13086,0.21289 36.827354,21.356503 79.346212 0 0 -14.17968,40.14062 36.827354,21.356503 79.346212 0 0 5.02148,15.24024 l 33.16992,8.88867 a 36.827354,21.356503 79.346212 0 0 3.78516,-32.02539 36.827354,21.356503 79.346212 0 0 -25.66602,-32.45703 z"
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4243"
cx="231.88249"
cy="951.51636"
r="10" />
<circle
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="path4245"
cx="227.71193"
cy="934.75916"
r="2.5" />
<circle
r="2.5"
cy="936.18604"
cx="236.51112"
id="circle4247"
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="circle4249"
cx="220.57744"
cy="940.46674"
r="2.5" />
</g>
<g
class='panda__paw panda__paw--left'
id="g4567">
<g
id="g4258"
transform="translate(-198.57651,-806.06781)"
style="opacity:1">
<path
id="path4260"
d="m 228.90463,923.66963 a 36.827354,21.356503 79.346212 0 0 -2.13086,0.21289 36.827354,21.356503 79.346212 0 0 -14.17968,40.14062 36.827354,21.356503 79.346212 0 0 5.02148,15.24024 l 33.16992,8.88867 a 36.827354,21.356503 79.346212 0 0 3.78516,-32.02539 36.827354,21.356503 79.346212 0 0 -25.66602,-32.45703 z"
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="circle4262"
cx="231.88249"
cy="951.51636"
r="10" />
<circle
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="circle4264"
cx="227.71193"
cy="934.75916"
r="2.5" />
<circle
r="2.5"
cy="936.18604"
cx="236.51112"
id="circle4266"
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<circle
style="opacity:1;fill:#ffaaaa;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="circle4268"
cx="220.57744"
cy="940.46674"
r="2.5" />
</g>
<g
id="g4472"
transform="matrix(0.94277935,-0.3334173,0.3334173,0.94277935,-41.21949,7.0330013)">
<g
transform="translate(0,-0.11890809)"
id="g4444">
<rect
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4440"
width="17.122164"
height="8.0175457"
x="-2.4852705"
y="143.95575" />
<rect
y="149.0688"
x="-2.4852705"
height="2.9044979"
width="17.122164"
id="rect4442"
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
transform="translate(17.722023,-0.11890809)"
id="g4448">
<rect
y="143.95575"
x="-2.4852705"
height="8.0175457"
width="17.122164"
id="rect4450"
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4452"
width="17.122164"
height="2.9044979"
x="-2.4852705"
y="149.0688" />
</g>
<g
id="g4454"
transform="translate(35.344023,-0.11890809)">
<rect
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4456"
width="17.122164"
height="8.0175457"
x="-2.4852705"
y="143.95575" />
<rect
y="149.0688"
x="-2.4852705"
height="2.9044979"
width="17.122164"
id="rect4458"
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
transform="translate(52.966023,-0.11890809)"
id="g4460">
<rect
y="143.95575"
x="-2.4852705"
height="8.0175457"
width="17.122164"
id="rect4462"
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4464"
width="17.122164"
height="2.9044979"
x="-2.4852705"
y="149.0688" />
</g>
<g
id="g4466"
transform="translate(70.588023,-0.11890809)">
<rect
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4468"
width="17.122164"
height="8.0175457"
x="-2.4852705"
y="143.95575" />
<rect
y="149.0688"
x="-2.4852705"
height="2.9044979"
width="17.122164"
id="rect4470"
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</g>
</g>
</g>
<g
transform="translate(27.242913,-63.41797)"
id="layer3" />
<g
transform="translate(13.322665,0)"
class='panda__paw panda__paw--hidden panda__paw--left-down'
id="g4886">
<g
transform="translate(13.920248,-63.41797)"
style="display:inline"
id="g4643">
<g
id="g4535"
transform="matrix(-0.78364181,-0.62121295,0.62121295,-0.78364181,-34.404531,343.71179)"
style="display:inline">
<g
transform="translate(0,-0.11890809)"
id="g4537">
<rect
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4539"
width="17.122164"
height="8.0175457"
x="-2.4852705"
y="143.95575" />
<rect
y="149.0688"
x="-2.4852705"
height="2.9044979"
width="17.122164"
id="rect4541"
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
transform="translate(17.722023,-0.11890809)"
id="g4543">
<rect
y="143.95575"
x="-2.4852705"
height="8.0175457"
width="17.122164"
id="rect4545"
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4547"
width="17.122164"
height="2.9044979"
x="-2.4852705"
y="149.0688" />
</g>
<g
id="g4549"
transform="translate(35.344023,-0.11890809)">
<rect
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4551"
width="17.122164"
height="8.0175457"
x="-2.4852705"
y="143.95575" />
<rect
y="149.0688"
x="-2.4852705"
height="2.9044979"
width="17.122164"
id="rect4553"
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<g
transform="translate(52.966023,-0.11890809)"
id="g4555">
<rect
y="143.95575"
x="-2.4852705"
height="8.0175457"
width="17.122164"
id="rect4557"
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4559"
width="17.122164"
height="2.9044979"
x="-2.4852705"
y="149.0688" />
</g>
<g
id="g4561"
transform="translate(70.588023,-0.11890809)">
<rect
style="opacity:1;fill:#66ff00;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4563"
width="17.122164"
height="8.0175457"
x="-2.4852705"
y="143.95575" />
<rect
y="149.0688"
x="-2.4852705"
height="2.9044979"
width="17.122164"
id="rect4565"
style="opacity:1;fill:#55d400;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</g>
<path
id="path4307"
d="m -6.8007074,202.10543 c -0.47928,-0.53664 -0.90823,-1.10833 -1.28523,-1.71292 -6.2383206,-10.00994 8.64615996,-29.03536 19.9581704,-37.60325 7.44973,-5.64254 18.49428,-8.77936 27.39901,-5.94343 7.63111,2.43031 16.0875,9.72596 16.21034,17.73378 0.16488,10.74817 -10.49332,17.89554 -21.01735,24.45862 -16.05208,10.00416 -33.88888044,11.32996 -41.2649404,3.0672 z"
style="opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
<rect
style="opacity:1;fill:#ff2a2a;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4856"
width="4.7469053"
height="15.596974"
x="18.992611"
y="147.15408"
ry="2.3734527" />
<rect
ry="2.3734527"
y="131.25748"
x="58.441982"
height="15.596974"
width="4.7469053"
id="rect4858"
style="opacity:1;fill:#ff2a2a;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.9316512,0.36335388,-0.36335388,0.9316512,0,0)" />
<rect
transform="matrix(0.39250978,0.91974783,-0.91974783,0.39250978,0,0)"
style="opacity:1;fill:#ff2a2a;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4860"
width="4.7469053"
height="15.596974"
x="122.84097"
y="52.115341"
ry="2.3734527" />
</g>
<g
class='panda__paw panda__paw--right-down panda__paw--hidden'
transform="translate(13.322665,0)"
id="g4910">
<path
transform="translate(13.920248,-63.41797)"
id="path4285"
d="m 188.60288,260.96193 c -0.47928,-0.53664 -0.90823,-1.10833 -1.28523,-1.71292 -6.23832,-10.00994 8.64616,-29.03536 19.95817,-37.60325 7.44973,-5.64254 18.49428,-8.77936 27.39901,-5.94343 7.63111,2.43031 16.0875,9.72596 16.21034,17.73378 0.16488,10.74817 -10.49332,17.89554 -21.01735,24.45862 -16.05208,10.00416 -33.88888,11.32996 -41.26494,3.0672 z"
style="display:inline;opacity:1;fill:#000000;fill-opacity:1;stroke:none;stroke-width:15;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
<rect
ry="2.3734527"
y="76.925354"
x="277.33405"
height="15.596974"
width="4.7469053"
id="rect4862"
style="opacity:1;fill:#ff2a2a;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
transform="matrix(0.87020846,0.49268371,-0.49268371,0.87020846,0,0)" />
<rect
transform="matrix(0.32671656,0.94512237,-0.94512237,0.32671656,0,0)"
style="opacity:1;fill:#ff2a2a;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4864"
width="4.7469053"
height="15.596974"
x="248.64572"
y="-121.71169"
ry="2.3734527" />
<rect
transform="matrix(0.99835797,-0.05728312,0.05728312,0.99835797,0,0)"
style="opacity:1;fill:#ff2a2a;fill-opacity:1;stroke:none;stroke-width:3;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
id="rect4866"
width="4.7469053"
height="15.596974"
x="203.8541"
y="219.75934"
ry="2.3734527" />
</g>
</svg>
<div class="panda__actions">
<button class="panda__paw-control"></button>
<button class="panda__paw-control"></button>
<button class="panda__paw-control"></button>
</div>
</div>
</div>
*
box-sizing border-box
body
background dodgerblue
min-height 100vh
.scene
align-items center
display flex
height 100vh
justify-content center
width 100vw
.panda
width 300px
&__wrap
position relative
&__actions
display flex
height 100%
left 0
opacity 0
position absolute
top 0
width 100%
&__paw
&-control
background transparent
cursor pointer
height 100%
flex 1
&--hidden
display none
const scene = document.querySelector('.scene')
const actions = document.querySelector('.panda__actions')
const paws = {
left: document.querySelector('.panda__paw--left'),
right: document.querySelector('.panda__paw--right'),
downLeft: document.querySelector('.panda__paw--left-down'),
downRight: document.querySelector('.panda__paw--right-down'),
}
const b1 = new Audio(
'https://freesound.org/data/previews/99/99751_29308-lq.mp3'
)
const b2 = new Audio(
'https://freesound.org/data/previews/99/99752_29308-lq.mp3'
)
const movePaws = movements => {
for (let i = 0; i < movements.length; i++) {
if (movements[i]) {
Object.entries(paws)[i][1].classList.remove('panda__paw--hidden')
} else {
Object.entries(paws)[i][1].classList.add('panda__paw--hidden')
}
}
}
const tap = e => {
e.stopPropagation()
const clicked = [...actions.children].indexOf(e.target)
const actionIndex = clicked !== -1 ? clicked : e.keyCode
switch (actionIndex) {
case 0:
case 37:
case 65:
// Tap left paw
movePaws([false, true, true, false])
b1.play()
break
case 1:
// Tap both paws
movePaws([false, false, true, true])
b1.play()
b2.play()
break
case 2:
case 39:
case 68:
// Tap right paw
movePaws([true, false, false, true])
b2.play()
break
default:
// Tap both paws
movePaws([false, false, true, true])
b1.play()
b2.play()
}
}
const unTap = e => {
e.stopPropagation()
movePaws([true, true, false, false])
b1.pause()
b1.currentTime = 0
b2.pause()
b2.currentTime = 0
}
const click = e => {
if (!e.button) {
movePaws([false, false, true, true])
b1.play()
b2.play()
}
if (e.button === 0) {
movePaws([false, true, true, false])
b1.play()
}
if (e.button === 2) {
movePaws([true, false, false, true])
b2.play()
}
}
const unClick = e => {
movePaws([true, true, false, false])
b1.pause()
b1.currentTime = 0
b2.pause()
b2.currentTime = 0
}
actions.addEventListener('mousedown', tap)
actions.addEventListener('mouseup', unTap)
actions.addEventListener('touchstart', tap)
actions.addEventListener('touchend', unTap)
scene.addEventListener('mousedown', click)
scene.addEventListener('mouseup', unClick)
scene.addEventListener('touchstart', click)
scene.addEventListener('touchend', unClick)
document.body.addEventListener('keydown', tap)
document.body.addEventListener('keyup', unTap)
scene.addEventListener('contextmenu', e => {
e.preventDefault()
return false
})
Also see: Tab Triggers