animation-fill-mode
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015å¹´9æâ©.
animation-fill-mode 㯠CSS ã®ããããã£ã§ã CSS ã¢ãã¡ã¼ã·ã§ã³ã®å®è¡ã®åå¾ã«ã©ã対象ã«ã¹ã¿ã¤ã«ãé©ç¨ããããè¨å®ãã¾ãã
試ãã¦ã¿ã¾ããã
animation-fill-mode: none;
animation-delay: 1s;
animation-fill-mode: forwards;
animation-delay: 1s;
animation-fill-mode: backwards;
animation-delay: 1s;
animation-fill-mode: both;
animation-delay: 1s;
<section class="flex-column" id="default-example">
<div>ã¢ãã¡ã¼ã·ã§ã³<span id="playstatus"></span></div>
<div id="example-element">ã¢ã¼ãã鏿ããã¨éå§ãã¾ãï¼</div>
</section>
#example-element {
background-color: #1766aa;
color: white;
margin: auto;
margin-left: 0;
border: 5px solid #333;
width: 150px;
height: 150px;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
#playstatus {
font-weight: bold;
}
.animating {
animation: slide 1s ease-in 1;
}
@keyframes slide {
from {
background-color: orange;
color: black;
margin-left: 0;
}
to {
background-color: orange;
color: black;
margin-left: 80%;
}
}
"use strict";
window.addEventListener("load", () => {
const el = document.getElementById("example-element");
const status = document.getElementById("playstatus");
function update() {
status.textContent = "å¾
æ©ä¸";
el.className = "";
window.requestAnimationFrame(() => {
window.requestAnimationFrame(() => {
el.className = "animating";
});
});
}
el.addEventListener("animationstart", () => {
status.textContent = "åä½ä¸";
});
el.addEventListener("animationend", () => {
status.textContent = "å®äº";
});
const observer = new MutationObserver(() => {
update();
});
observer.observe(el, {
attributes: true,
attributeFilter: ["style"],
});
update();
});
ã¢ãã¡ã¼ã·ã§ã³ã®ããããã£ãã¹ã¦ãä¸åº¦ã«è¨å®ããã«ã¯ã䏿¬æå®ããããã£ã§ãã animation ã使ç¨ããã¨ä¾¿å©ã§ãã
æ§æ
/* åä¸ã®ã¢ãã¡ã¼ã·ã§ã³ */
animation-fill-mode: none;
animation-fill-mode: forwards;
animation-fill-mode: backwards;
animation-fill-mode: both;
/* è¤æ°ã®ã¢ãã¡ã¼ã·ã§ã³ */
animation-fill-mode: none, backwards;
animation-fill-mode: both, forwards, none;
/* ã°ãã¼ãã«å¤ */
animation-fill-mode: inherit;
animation-fill-mode: initial;
animation-fill-mode: revert;
animation-fill-mode: revert-layer;
animation-fill-mode: unset;
å¤
none-
ã¢ãã¡ã¼ã·ã§ã³ãå®è¡ããã¦ããªãæã¯ã対象ã«ã¹ã¿ã¤ã«ãé©ç¨ãã¾ãããè¦ç´ ã¯é©ç¨ããã¦ãããã®ä»ã® CSS è¦åã使ç¨ãã¦è¡¨ç¤ºããã¾ãããããæ¢å®å¤ã§ãã
forwards-
対象ã¯å®è¡ã®æå¾ã®ãã¼ãã¬ã¼ã ã§è¨å®ãããè¨ç®å¤ãä¿æãã¾ããæå¾ã®ãã¼ãã¬ã¼ã ã¯
animation-directionã¨animation-iteration-countã®å¤ã«ãã£ã¦å¤ããã¾ããanimation-directionanimation-iteration-countæå¾ã®ãã¼ãã¬ã¼ã normalå¶æ°ã¾ãã¯å¥æ° 100%ã¾ãã¯toreverseå¶æ°ã¾ãã¯å¥æ° 0%ã¾ãã¯fromalternateå¶æ° 0%ã¾ãã¯fromalternate奿° 100%ã¾ãã¯toalternate-reverseå¶æ° 100%ã¾ãã¯toalternate-reverse奿° 0%ã¾ãã¯fromã¢ãã¡ã¼ã·ã§ã³ããããããã£ã¯ãè¨å®ããã
will-changeããããã£ã®å¤ã«å«ãããããã®ããã«åä½ãã¾ããã¢ãã¡ã¼ã·ã§ã³ä¸ã«æ°ããéãåããã³ã³ããã¹ãã使ãããå ´åãã¢ãã¡ã¼ã·ã§ã³ãå®äºããå¾ãã対象è¦ç´ ã¯éãåããã³ã³ããã¹ããä¿æãã¾ãã backwards-
ã¢ãã¡ã¼ã·ã§ã³ã¯æåã®é©åãªãã¼ãã¬ã¼ã ã§å®ç¾©ãããå¤ã対象ã«é©ç¨ãããã¨åæã«é©ç¨ãã
animation-delayã®æéãããä¿æãã¾ããæåã®é©åãªãã¼ãã¬ã¼ã ã¯ãanimation-directionã®å¤ã«ãã£ã¦å¤ããã¾ããanimation-directionæåã®é©åãªãã¼ãã¬ã¼ã normalã¾ãã¯alternate0%ã¾ãã¯fromreverseã¾ãã¯alternate-reverse100%ã¾ãã¯to both-
ã¢ãã¡ã¼ã·ã§ã³ã¯ forwards 㨠backwards ã®ä¸¡æ¹ã®æ¢å®ã«å¾ãã¾ãããã£ã¦ãã¢ãã¡ã¼ã·ã§ã³ã®è¨å®ã¯å®è¡åã¨å®è¡å¾ã®ä¸¡æ¹ã«é©ç¨ããã¾ãã
ã¡ã¢:
animation-* ããããã£ã«ã«ã³ãåºåãã§è¤æ°ã®å¤ãæå®ããå ´åã animation-name ã«ç¾ããé ã«ã¢ãã¡ã¼ã·ã§ã³ã«é©ç¨ããã¾ããã¢ãã¡ã¼ã·ã§ã³ã®æ°ã¨ animation-* ããããã£ã®å¤ãä¸è´ããªãå ´åã¯ãè¤æ°ã®ã¢ãã¡ã¼ã·ã§ã³ããããã£å¤ã®è¨å® ãåç
§ãã¦ãã ããã
ã¡ã¢:
animation-fill-mode 㯠CSS ã¹ã¯ãã¼ã«é§åã¢ãã¡ã¼ã·ã§ã³ã使ããã¨ãã«ãéå¸¸ã®æéãã¼ã¹ã®ã¢ãã¡ã¼ã·ã§ã³ã¨åã广ãããã¾ãã
å ¬å¼å®ç¾©
| åæå¤ | none |
|---|---|
| é©ç¨å¯¾è±¡ | ãã¹ã¦ã®è¦ç´ ã::before / ::after æ¬ä¼¼è¦ç´ |
| ç¶æ¿ | ãªã |
| è¨ç®å¤ | æå®éã |
| ã¢ãã¡ã¼ã·ã§ã³ã®ç¨®é¡ | ã¢ãã¡ã¼ã·ã§ã³ä¸å¯ |
形弿æ³
animation-fill-mode =
<single-animation-fill-mode>#
<single-animation-fill-mode> =
none |
forwards |
backwards |
both
ä¾
>fill ã¢ã¼ãã®è¨å®
以ä¸ã®ä¾ã§ animation-fill-mode ã®å¹æãè¦ããã¨ãã§ãã¾ããããã¯ç¡éã«ç¹°ãè¿ãããã¢ãã¡ã¼ã·ã§ã³ããå
ã®ç¶æ
ã«æ»ãã®ã§ã¯ãªãæå¾ã®ç¶æ
ãç¶æããããã«ãããã¨ãã§ãã¾ãï¼æ¢å®ã®ç¶æ
ï¼ã
HTML
<p>ãã¦ã¹ãç°è²ã®ããã¯ã¹ã®ä¸ã«ä¹ãã¦ãã ããï¼</p>
<div class="demo">
<div class="grows-and-stays">ããã¯å¤§ãããªã£ã¦å¤§ããã¾ã¾ã«ãªãã¾ãã</div>
<div class="grows">ããã¯å¤§ãããªãã ãã§ãã</div>
</div>
CSS
.demo {
border-top: 100px solid #ccc;
height: 300px;
}
@keyframes grow {
0% {
font-size: 0;
}
100% {
font-size: 40px;
}
}
.demo:hover .grows {
animation-name: grow;
animation-duration: 3s;
}
.demo:hover .grows-and-stays {
animation-name: grow;
animation-duration: 3s;
animation-fill-mode: forwards;
}
çµæ
ãã以å¤ã®ä¾ã¯ CSS ã¢ãã¡ã¼ã·ã§ã³ãåç §ãã¦ãã ããã
仿§æ¸
| Specification |
|---|
| CSS Animations Level 1 > # animation-fill-mode > |
ãã©ã¦ã¶ã¼ã®äºææ§
é¢é£æ å ±
- CSS ã¢ãã¡ã¼ã·ã§ã³ã®ä½¿ç¨
- JavaScript ã®
AnimationEventAPI - ãã®ä»ã®ã¢ãã¡ã¼ã·ã§ã³é¢é£ããããã£:
animation,animation-composition,animation-delay,animation-direction,animation-duration,animation-iteration-count,animation-name,animation-play-state,animation-timeline,animation-timing-function