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 URL's 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 it's URL and the proper URL extention.
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="microwave">
<div class="door">
<div class="glass"></div>
<div class="handle"></div>
</div>
<div class="menu">
<div class="screen">
<span class="progress"></span>
</div>
<button class="start">Start</button>
<button class="clear">Clear</button>
</div>
<div class="smoke">
<span class="s0"></span>
<span class="s1"></span>
<span class="s2"></span>
<span class="s3"></span>
<span class="s4"></span>
<span class="s5"></span>
<span class="s6"></span>
<span class="s7"></span>
<span class="s8"></span>
<span class="s9"></span>
</div>
</div>
html,
body {
margin: 0;
width: 100%;
height: 100%;
}
body {
background: linear-gradient(to right, #007991, #78ffd6); /* https://uigradients.com/#ChittyChittyBangBang */
}
.microwave {
position: absolute;
top: 50%;
left: 50%;
display: flex;
background: grey;
width: 90vmin;
height: 50vmin;
transform: translate(-50%, -50%);
}
.microwave::before {
content: '';
position: absolute;
top: 50%;
left: 4vmin;
width: calc(100% - 8vmin);
height: 75%;
background: black;
transform: translateY(-50%);
border-radius: 2vmin;
}
.door {
position: relative;
flex: 0 0 75%;
border-right: solid 3px white;
}
.handle {
position: absolute;
top: calc(5vmin - 1.5px);
right: 3.5vmin;
width: 4vmin;
height: calc(100% - 10vmin);
background: grey;
border-radius: 2vmin;
border: solid 3px white;
}
.glass {
position: absolute;
top: 50%;
left: 8vmin;
width: 70%;
height: calc(70% - 5vmin);
background-color: white;
transform: translateY(-50%);
}
.running .glass {
background-color: lightyellow;
}
.menu {
flex: 0 0 25%;
position: relative;
}
.start,
.clear {
position: absolute;
bottom: 17.5%;
right: 4.5vmin;
width: 80%;
color: white;
height: 5vmin;
background: transparent;
border: none;
text-transform: uppercase;
text-align: center;
font-size: 3.5vmin;
}
.clear {
display: none;
color: red;
}
.running .start { display: none; }
.running .clear { display: block; }
.screen {
position: absolute;
top: 20%;
right: 6.5vmin;
width: 60%;
height: 5vmin;
background: white;
}
.progress {
position: absolute;
top: 3px;
left: 3px;
width: calc(100% - 6px);
height: calc(100% - 6px);
background: #78ffd6;
transform-origin: 0 50%;
transform: scaleX(0);
}
.running .progress {
transform: scaleX(1);
transition: transform 2s linear;
}
.smoke {
position: absolute;
width: 0;
height: 0;
left: 37%;
top: 8.5vmin;
}
.smoke span {
display: block;
position: absolute;
bottom: -35px; left: 50%; margin-left:-20px;
height: 0px; width: 0px;
border: 35px solid #4b4b4b;
border-radius: 35px;
left: -14px; opacity: 0;
transform: scale(0.2);
}
@keyframes fumeeG {
0% { transform: scale(0.2) translate(0, 0) }
10% { opacity: 1; transform: scale(0.2) translate(0, -5px) }
100% { opacity: 0; transform: scale(1) translate(-20px, -130px) }
}
@keyframes fumeeD {
0% { transform: scale(0.2) translate(0, 0) }
10% { opacity: 1; transform: scale(0.2) translate(0, -5px) }
100% { opacity: 0; transform: scale(1) translate(20px, -130px) }
}
.cancel .smoke .s0 { animation: fumeeG 10s 0s }
.cancel .smoke .s1 { animation: fumeeD 10s 1s }
.cancel .smoke .s2 { animation: fumeeG 10s 2s }
.cancel .smoke .s3 { animation: fumeeD 10s 3s }
.cancel .smoke .s4 { animation: fumeeG 10s 4s }
.cancel .smoke .s5 { animation: fumeeD 10s 5s }
.cancel .smoke .s6 { animation: fumeeG 10s 6s }
.cancel .smoke .s7 { animation: fumeeD 10s 7s }
.cancel .smoke .s8 { animation: fumeeG 10s 8s }
.cancel .smoke .s9 { animation: fumeeD 10s 9s }
/*
Pour cet exercice, vous n'avez qu'à ajouter du JS (Nul besoin de modifier le HTML ou le CSS).
1. Lorsque la transition sur l'élément progrès débute, il faut déclencher le son 'marche'.
2. Lorsque la transition est terminée, retirer la classe 'en-marche' sur l'élément <body>, mettre le son 'marche' à pause et déclencher le son 'ding'.
3. Si l'usager appuie sur le bouton 'clear' pendant la transition, mettre le son 'marche à pause', retirer la classe 'en-marche' sur l'élément <body>. La transition sera ainsi cancellée. Écouter cet événement et si l'elapsedTime est inférieur à '2' (soit la durée de l'animation), ajouter la classe 'oups' au <body>.
Résultat attendu 👉 https://gph.is/g/apQVR2Q
Bonne chance
*/
const start = document.querySelector('.start');
var ding = new Audio('https://ex.smnarnold.com/animations-transitions/ding.mp3');
var marche = new Audio('https://ex.smnarnold.com/animations-transitions/mirco-onde.mp3');
start.addEventListener('click', function() {
document.body.classList.add('running');
document.body.classList.remove('cancel');
});
Also see: Tab Triggers