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="control-panel">
<div class="change-color"></div>
</div>
<div class="container">
<div class="tamagotchi">
<div class="left separation"></div>
<div class="name">
<span class="initial">T</span>a<span class="m">m</span>agotc<span class="h">h</span>i
</div>
<div class="tamagotchi-inner">
<div class="screen">
<div class="top">
<div class="food item"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="utensils" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 416 512" class="svg-inline--fa fa-utensils fa-w-13 fa-5x"><path fill="currentColor" d="M207.9 15.2c.8 4.6 16.1 94.5 16.1 128.8 0 52.3-27.8 89.6-68.9 104.6L168 486.7c.7 13.7-10.2 25.3-24 25.3H80c-13.7 0-24.7-11.5-24-25.3l12.9-238.1C27.7 233.6 0 196.2 0 144 0 109.6 15.3 19.9 16.1 15.2 19.3-5.1 61.4-5.4 64 16.3v141.2c1.3 3.4 15.1 3.2 16 0 1.4-25.3 7.9-139.2 8-141.8 3.3-20.8 44.7-20.8 47.9 0 .2 2.7 6.6 116.5 8 141.8.9 3.2 14.8 3.4 16 0V16.3c2.6-21.6 44.8-21.4 48-1.1zm119.2 285.7l-15 185.1c-1.2 14 9.9 26 23.9 26h56c13.3 0 24-10.7 24-24V24c0-13.2-10.7-24-24-24-82.5 0-221.4 178.5-64.9 300.9z" class=""></path></svg>
</div>
<div class="light item"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="lightbulb" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512" class="svg-inline--fa fa-lightbulb fa-w-11 fa-3x"><path fill="currentColor" d="M96.06 454.35c.01 6.29 1.87 12.45 5.36 17.69l17.09 25.69a31.99 31.99 0 0 0 26.64 14.28h61.71a31.99 31.99 0 0 0 26.64-14.28l17.09-25.69a31.989 31.989 0 0 0 5.36-17.69l.04-38.35H96.01l.05 38.35zM0 176c0 44.37 16.45 84.85 43.56 115.78 16.52 18.85 42.36 58.23 52.21 91.45.04.26.07.52.11.78h160.24c.04-.26.07-.51.11-.78 9.85-33.22 35.69-72.6 52.21-91.45C335.55 260.85 352 220.37 352 176 352 78.61 272.91-.3 175.45 0 73.44.31 0 82.97 0 176zm176-80c-44.11 0-80 35.89-80 80 0 8.84-7.16 16-16 16s-16-7.16-16-16c0-61.76 50.24-112 112-112 8.84 0 16 7.16 16 16s-7.16 16-16 16z" class=""></path></svg>
</div>
<div class="game item"><svg aria-hidden="true" focusable="false" data-prefix="fab" data-icon="steam" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512" class="svg-inline--fa fa-steam fa-w-16 fa-3x"><path fill="currentColor" d="M496 256c0 137-111.2 248-248.4 248-113.8 0-209.6-76.3-239-180.4l95.2 39.3c6.4 32.1 34.9 56.4 68.9 56.4 39.2 0 71.9-32.4 70.2-73.5l84.5-60.2c52.1 1.3 95.8-40.9 95.8-93.5 0-51.6-42-93.5-93.7-93.5s-93.7 42-93.7 93.5v1.2L176.6 279c-15.5-.9-30.7 3.4-43.5 12.1L0 236.1C10.2 108.4 117.1 8 247.6 8 384.8 8 496 119 496 256zM155.7 384.3l-30.5-12.6a52.79 52.79 0 0 0 27.2 25.8c26.9 11.2 57.8-1.6 69-28.4 5.4-13 5.5-27.3.1-40.3-5.4-13-15.5-23.2-28.5-28.6-12.9-5.4-26.7-5.2-38.9-.6l31.5 13c19.8 8.2 29.2 30.9 20.9 50.7-8.3 19.9-31 29.2-50.8 21zm173.8-129.9c-34.4 0-62.4-28-62.4-62.3s28-62.3 62.4-62.3 62.4 28 62.4 62.3-27.9 62.3-62.4 62.3zm.1-15.6c25.9 0 46.9-21 46.9-46.8 0-25.9-21-46.8-46.9-46.8s-46.9 21-46.9 46.8c.1 25.8 21.1 46.8 46.9 46.8z"></path></svg>
</div>
<div class="medkit item"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="medkit" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-medkit fa-w-16 fa-3x"><path fill="currentColor" d="M96 480h320V128h-32V80c0-26.51-21.49-48-48-48H176c-26.51 0-48 21.49-48 48v48H96v352zm96-384h128v32H192V96zm320 80v256c0 26.51-21.49 48-48 48h-16V128h16c26.51 0 48 21.49 48 48zM64 480H48c-26.51 0-48-21.49-48-48V176c0-26.51 21.49-48 48-48h16v352zm288-208v32c0 8.837-7.163 16-16 16h-48v48c0 8.837-7.163 16-16 16h-32c-8.837 0-16-7.163-16-16v-48h-48c-8.837 0-16-7.163-16-16v-32c0-8.837 7.163-16 16-16h48v-48c0-8.837 7.163-16 16-16h32c8.837 0 16 7.163 16 16v48h48c8.837 0 16 7.163 16 16z" ></path></svg>
</div>
</div>
<div class="middle">
<div class="pet"></div>
<div class="shit"></div>
</div>
<div class="bottom">
<div class="bath item"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="bath" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-bath fa-w-16 fa-3x"><path fill="currentColor" d="M32,384a95.4,95.4,0,0,0,32,71.09V496a16,16,0,0,0,16,16h32a16,16,0,0,0,16-16V480H384v16a16,16,0,0,0,16,16h32a16,16,0,0,0,16-16V455.09A95.4,95.4,0,0,0,480,384V336H32ZM496,256H80V69.25a21.26,21.26,0,0,1,36.28-15l19.27,19.26c-13.13,29.88-7.61,59.11,8.62,79.73l-.17.17A16,16,0,0,0,144,176l11.31,11.31a16,16,0,0,0,22.63,0L283.31,81.94a16,16,0,0,0,0-22.63L272,48a16,16,0,0,0-22.62,0l-.17.17c-20.62-16.23-49.83-21.75-79.73-8.62L150.22,20.28A69.25,69.25,0,0,0,32,69.25V256H16A16,16,0,0,0,0,272v16a16,16,0,0,0,16,16H496a16,16,0,0,0,16-16V272A16,16,0,0,0,496,256Z" class=""></path></svg>
</div>
<div class="weight item"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="weight" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" class="svg-inline--fa fa-weight fa-w-16 fa-3x"><path fill="currentColor" d="M448 64h-25.98C438.44 92.28 448 125.01 448 160c0 105.87-86.13 192-192 192S64 265.87 64 160c0-34.99 9.56-67.72 25.98-96H64C28.71 64 0 92.71 0 128v320c0 35.29 28.71 64 64 64h384c35.29 0 64-28.71 64-64V128c0-35.29-28.71-64-64-64zM256 320c88.37 0 160-71.63 160-160S344.37 0 256 0 96 71.63 96 160s71.63 160 160 160zm-.3-151.94l33.58-78.36c3.5-8.17 12.94-11.92 21.03-8.41 8.12 3.48 11.88 12.89 8.41 21l-33.67 78.55C291.73 188 296 197.45 296 208c0 22.09-17.91 40-40 40s-40-17.91-40-40c0-21.98 17.76-39.77 39.7-39.94z" class=""></path></svg>
</div>
<div class="angry item"><svg aria-hidden="true" focusable="false" data-prefix="far" data-icon="angry" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 496 512" class="svg-inline--fa fa-angry fa-w-16 fa-3x"><path fill="currentColor" d="M248 8C111 8 0 119 0 256s111 248 248 248 248-111 248-248S385 8 248 8zm0 448c-110.3 0-200-89.7-200-200S137.7 56 248 56s200 89.7 200 200-89.7 200-200 200zm0-144c-33.6 0-65.2 14.8-86.8 40.6-8.5 10.2-7.1 25.3 3.1 33.8s25.3 7.2 33.8-3c24.8-29.7 75-29.7 99.8 0 8.1 9.7 23.2 11.9 33.8 3 10.2-8.5 11.5-23.6 3.1-33.8-21.6-25.8-53.2-40.6-86.8-40.6zm-48-72c10.3 0 19.9-6.7 23-17.1 3.8-12.7-3.4-26.1-16.1-29.9l-80-24c-12.8-3.9-26.1 3.4-29.9 16.1-3.8 12.7 3.4 26.1 16.1 29.9l28.2 8.5c-3.1 4.9-5.3 10.4-5.3 16.6 0 17.7 14.3 32 32 32s32-14.4 32-32.1zm199-54.9c-3.8-12.7-17.1-19.9-29.9-16.1l-80 24c-12.7 3.8-19.9 17.2-16.1 29.9 3.1 10.4 12.7 17.1 23 17.1 0 17.7 14.3 32 32 32s32-14.3 32-32c0-6.2-2.2-11.7-5.3-16.6l28.2-8.5c12.7-3.7 19.9-17.1 16.1-29.8z" class=""></path></svg>
</div>
<div class="attention item"><svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="exclamation-triangle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" class="svg-inline--fa fa-exclamation-triangle fa-w-18 fa-3x"><path fill="currentColor" d="M569.517 440.013C587.975 472.007 564.806 512 527.94 512H48.054c-36.937 0-59.999-40.055-41.577-71.987L246.423 23.985c18.467-32.009 64.72-31.951 83.154 0l239.94 416.028zM288 354c-25.405 0-46 20.595-46 46s20.595 46 46 46 46-20.595 46-46-20.595-46-46-46zm-43.673-165.346l7.418 136c.347 6.364 5.609 11.346 11.982 11.346h48.546c6.373 0 11.635-4.982 11.982-11.346l7.418-136c.375-6.874-5.098-12.654-11.982-12.654h-63.383c-6.884 0-12.356 5.78-11.981 12.654z" class=""></path></svg>
</div>
</div>
</div>
</div>
<div class="right separation"></div>
<div class="buttons-container">
<div class="left button"></div>
<div class="middle button"></div>
<div class="right button"></div>
</div>
</div>
</div>
<div class="created">
<span>Created by</span>
<a href="https://manz.dev/"><h2>Manz.dev</h2></a>
<p>on <a href="https://twitch.tv/ManzDev">Twitch</a> / <a href="https://youtu.be/39qlI5eeajQ">Youtube</a></p>
</div>
@use postcss-nested;
@font-face {
font-family: "My Chemical Romance";
src:
local("My Chemical Romance"),
url("https://manzdev.github.io/twitch-tamagotchi/my-chemical-romance.woff2") format("woff2"),
url("https://manzdev.github.io/twitch-tamagotchi/my-chemical-romance.woff") format("woff");
font-display: swap;
}
:root {
--body-color: darkred;
--inner-color: silver;
--lcd-bgcolor: #b8b3af;
--buttons-color: gold;
--width: 275px;
--height: 325px;
--title-font-size: 34px;
--break-shape: polygon(0 60%, 9% 38%, 10% 12%, 29% 15%, 47% 9%, 70% 14%, 84% 7%, 97% 20%, 91% 35%, 100% 58%, 92% 72%, 87% 92%, 68% 90%, 50% 100%, 40% 91%, 25% 94%, 9% 85%, 11% 77%);
}
.container {
display: flex;
justify-content: center;
margin-top: 3em;
}
.tamagotchi {
background-color: var(--body-color);
width: var(--width);
height: var(--height);
border-radius: 300px / 410px 410px 300px 300px;
box-shadow:
0 0 20px rgba(0, 0, 0, 0.75),
0 0 40px 15px rgba(0, 0, 0, 0.25) inset;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
position: relative;
&::before,
&::after {
position: absolute;
content: "";
width: 50px;
height: 100px;
background: #fff4;
clip-path: ellipse(28px 80px at 0 50%);
filter: blur(32px);
}
&::before {
left: 0;
transform: scaleX(-1) rotate(-5deg);
}
&::after {
right: 0;
transform: rotate(-5deg);
}
& .separation {
border-bottom: 7px solid rgba(0, 0, 0, 0.65);
width: 34%;
height: 25px;
position: absolute;
}
& .left.separation {
left: 1px;
transform: translateY(30px) rotate(6deg);
border-radius: 50%;
}
& .right.separation {
right: 0;
transform: translateY(26px) rotate(-6deg);
border-radius: 50%;
}
& .name {
font-family: "My Chemical Romance", sans-serif;
font-size: var(--title-font-size);
font-variant: small-caps;
letter-spacing: -2px;
color: var(--buttons-color);
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.75);
transform: translateY(15px);
& .initial {
display: inline-block;
transform: skewX(339deg) translate(6px);
}
& .m {
display: inline-block;
transform: skewX(342deg) translate(1px, 3px);
}
& .h {
display: inline-block;
font-size: calc(var(--title-font-size) * 1.3);
}
}
& .tamagotchi-inner {
background: rgba(0, 0, 0, 0.65);
width: calc(var(--width) * 0.62);
height: calc(var(--height) * 0.54);
clip-path: var(--break-shape);
transform: translate(4px, 0);
position: relative;
z-index: 5;
display: flex;
justify-content: center;
align-items: center;
&::before {
content: "";
display: block;
width: 100%;
height: 100%;
background: var(--inner-color);
clip-path: var(--break-shape);
transform: scale(0.95);
}
& .screen {
--border-radius: 10px;
width: 125px;
height: 120px;
background: var(--lcd-bgcolor);
position: absolute;
border-radius: var(--border-radius);
transform: translateY(4px);
display: flex;
flex-direction: column;
justify-content: space-between;
overflow: hidden;
&::after {
content: "";
display: block;
width: 100%;
height: 100%;
box-shadow:
0 0 10px rgba(0, 0, 0, 0.5) inset,
0 0 5px 2px rgba(0, 0, 0, 0.25) inset;
position: absolute;
border-radius: var(--border-radius);
pointer-events: none;
}
& .top,
& .bottom {
background: #a6a6a6;
height: 32px;
display: flex;
justify-content: space-around;
padding: 0 6px;
}
& .middle {
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 100%;
& .pet {
width: 42%;
height: 100%;
transform: scale(0.8);
&::before {
--pet-color: #222;
content: "";
display: block;
width: 4px;
height: 4px;
box-shadow:
20px 0 0 var(--pet-color),
24px 0 0 var(--pet-color),
28px 0 0 var(--pet-color),
32px 0 0 var(--pet-color),
36px 0 0 var(--pet-color),
16px 4px 0 var(--pet-color),
40px 4px 0 var(--pet-color),
4px 8px 0 var(--pet-color),
8px 8px 0 var(--pet-color),
12px 8px 0 var(--pet-color),
20px 8px 0 var(--pet-color),
36px 8px 0 var(--pet-color),
44px 8px 0 var(--pet-color),
0 12px 0 var(--pet-color),
48px 12px 0 var(--pet-color),
4px 16px 0 var(--pet-color),
8px 16px 0 var(--pet-color),
12px 16px 0 var(--pet-color),
48px 16px 0 var(--pet-color),
0 20px 0 var(--pet-color),
48px 20px 0 var(--pet-color),
4px 24px 0 var(--pet-color),
8px 24px 0 var(--pet-color),
12px 24px 0 var(--pet-color),
48px 24px 0 var(--pet-color),
12px 28px 0 var(--pet-color),
32px 28px 0 var(--pet-color),
40px 28px 0 var(--pet-color),
52px 28px 0 var(--pet-color),
12px 32px 0 var(--pet-color),
32px 32px 0 var(--pet-color),
40px 32px 0 var(--pet-color),
52px 32px 0 var(--pet-color),
12px 36px 0 var(--pet-color),
36px 36px 0 var(--pet-color),
52px 36px 0 var(--pet-color),
16px 40px 0 var(--pet-color),
48px 40px 0 var(--pet-color),
20px 44px 0 var(--pet-color),
28px 44px 0 var(--pet-color),
32px 44px 0 var(--pet-color),
36px 44px 0 var(--pet-color),
44px 44px 0 var(--pet-color),
20px 48px 0 var(--pet-color),
28px 48px 0 var(--pet-color),
36px 48px 0 var(--pet-color),
44px 48px 0 var(--pet-color),
24px 52px 0 var(--pet-color),
40px 52px 0 var(--pet-color);
animation: movePet 1s infinite steps(2);
}
}
& .shit {
width: 36px;
height: 32px;
align-self: flex-end;
transform: translate(10px, 0) scale(0.6);
&::before {
content: "";
display: block;
width: 4px;
height: 4px;
animation: moveShit 1s infinite steps(2, jump-none);
}
}
}
& .item svg {
width: 20px;
height: 20px;
margin: 6px 5px;
opacity: 0.25;
&:hover {
opacity: 0.75;
}
}
}
}
& .buttons-container {
width: 40%;
height: 32px;
margin-top: 5px;
display: flex;
justify-content: space-between;
& .button {
width: 22px;
height: 22px;
border-radius: 50%;
background: var(--buttons-color);
box-shadow:
0 0 4px 2px rgba(0, 0, 0, 0.75),
-2px -2px 4px rgba(0, 0, 0, 0.5) inset;
&:active {
background-image: linear-gradient(rgba(0, 0, 0, 0.1), rgba(0, 0, 0, 0.1));
box-shadow:
0 0 4px 2px rgba(0, 0, 0, 0.75),
2px 2px 2px rgba(0, 0, 0, 0.25) inset;
}
&.middle {
align-self: flex-end;
}
}
}
}
.change-color {
width: 255px;
margin: auto;
& button {
width: 45px;
height: 45px;
background: var(--color);
border: 0;
border-radius: 12px;
margin: 3px;
box-shadow: -2px -2px 2px 4px rgba(0, 0, 0, 0.25) inset;
& span {
display: none;
}
}
}
@keyframes movePet {
0% {
transform: translate(40px, 0) rotateY(180deg);
}
100% {
transform: translate(-20px, 0) rotateY(-180deg);
}
}
@keyframes moveShit {
0% {
box-shadow:
32px 0 0 #000,
4px 4px 0 #000,
28px 4px 0 #000,
0 8px 0 #000,
32px 8px 0 #000,
4px 12px 0 #000,
16px 12px 0 #000,
16px 16px 0 #000,
20px 16px 0 #000,
8px 20px 0 #000,
12px 20px 0 #000,
16px 20px 0 #000,
24px 20px 0 #000,
4px 24px 0 #000,
8px 24px 0 #000,
12px 24px 0 #000,
16px 24px 0 #000,
20px 24px 0 #000,
28px 24px 0 #000,
4px 28px 0 #000,
8px 28px 0 #000,
12px 28px 0 #000,
16px 28px 0 #000,
20px 28px 0 #000,
24px 28px 0 #000,
28px 28px 0 #000;
}
100% {
box-shadow:
0 0 0 #000,
4px 4px 0 #000,
28px 4px 0 #000,
0 8px 0 #000,
32px 8px 0 #000,
16px 12px 0 #000,
28px 12px 0 #000,
16px 16px 0 #000,
20px 16px 0 #000,
8px 20px 0 #000,
12px 20px 0 #000,
16px 20px 0 #000,
24px 20px 0 #000,
4px 24px 0 #000,
12px 24px 0 #000,
16px 24px 0 #000,
20px 24px 0 #000,
24px 24px 0 #000,
28px 24px 0 #000,
4px 28px 0 #000,
8px 28px 0 #000,
12px 28px 0 #000,
16px 28px 0 #000,
20px 28px 0 #000,
24px 28px 0 #000,
28px 28px 0 #000;
}
}
.created {
background:
url(https://assets.codepen.io/154065/internal/avatars/users/default.png),
linear-gradient(to bottom, #884ced, #ec1cce);
background-size: 75px 75px, cover;
background-repeat: no-repeat;
position: absolute;
top: 0;
right: 0;
width: 250px;
height: 75px;
display: flex;
flex-direction: column;
align-items: center;
padding-left: 2em;
& span,
& h2,
& p,
& a {
font-family: Montserrat;
margin: 0;
}
& a,
& p,
& span {
color: #fff;
}
& h2 {
font-weight: 700;
transform: translate(0, -4px);
}
& a {
text-decoration-color: rgba(255,255,255,0.4);
}
& a:hover {
color: #e6e82a;
}
}
/*
Typograph: https://www.deviantart.com/excessts/art/My-chemical-romance-55579208
*/
const COLORS_BUTTON = [
{ text: "Rojo", color: "#890000", buttonsColor: "gold" },
{ text: "Turquesa", color: "#19B1AC", buttonsColor: "#ccc" },
{ text: "Negro", color: "#111", buttonsColor: "#bbb" },
{ text: "Azul", color: "#001F91", buttonsColor: "#ddd" },
{ text: "Amarillo", color: "#d68111", buttonsColor: "#1836a3" }
];
const changeColor = document.querySelector(".change-color");
const tamagotchi = document.querySelector(".tamagotchi");
changeColor.innerHTML = COLORS_BUTTON.map(color => {
return `<button style="--color: ${color.color}; --text-color: ${color.buttonsColor}">
<span>${color.text}</span>
</button>`;
}).join("");
const buttons = Array.from(document.querySelectorAll("button"));
buttons.forEach((button, index) => {
button.addEventListener("click", () => {
tamagotchi.style.setProperty("--body-color", COLORS_BUTTON[index].color);
tamagotchi.style.setProperty("--buttons-color", COLORS_BUTTON[index].buttonsColor);
});
});
Also see: Tab Triggers