| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/API/Web_Animations_API/Tips | [Back] [Original] |
Get to know MDN better
CSS animation-play-state "running" JavaScript
HTML <div>
<div class="box"></div>
<button class="runButton"></button>
CSS
.box {
width: 100px;
height: 100px;
border: 1px solid black;
margin-bottom: 1rem;
}
JavaScript playAnimation() @keyframes JavaScript
const box = document.querySelector(".box");
const button = document.querySelector(".runButton");
/*
CSS @keyframes
@keyframes colorChange {
0% {
background-color: grey;
}
100% {
background-color: lime;
}
}
*/
const colorChangeFrames = { backgroundColor: ["grey", "lime"] };
function playAnimation() {
box.animate(colorChangeFrames, 4000);
}
playAnimation Element.animate() animate() colorChangeFrames
button.addEventListener("click", playAnimation);
0% from run finish animation-iteration
playAnimation() finish
<div class="box"></div>
<button class="runButton"></button>
.box {
width: 100px;
height: 100px;
border: 1px solid black;
margin-bottom: 1rem;
}
const box = document.querySelector(".box");
const button = document.querySelector(".runButton");
const colorChangeFrames = { backgroundColor: ["grey", "lime"] };
button.addEventListener("click", playAnimation);
function playAnimation() {
button.setAttribute("disabled", true);
const anim = box.animate(colorChangeFrames, 4000);
anim.addEventListener("finish", (event) => {
button.removeAttribute("disabled");
});
}
CSS will-change will-change
animation-fill-mode: forwards both will-change
| Web Proxy Viewer | New URL | Original Page |