animation
åºçº¿
广æ³å¯ç¨
*
èª 2015å¹´9æ èµ·ï¼æ¤ç¹æ§å·²å¨ä¸»æµæµè§å¨ä¸å¾å°æ¯æï¼å¯å¨å¤§å¤æ°è®¾å¤åæµè§å¨çæ¬ä¸æ£å¸¸ä½¿ç¨ã
* æ¤ç¹æ§çæäºé¨åçæ¯æç¨åº¦å¯è½ææä¸åã
CSS animation 屿§æ¯ animation-nameï¼animation-duration, animation-timing-functionï¼animation-delayï¼animation-iteration-countï¼animation-directionï¼animation-fill-mode å animation-play-state 屿§çä¸ä¸ªç®å屿§å½¢å¼ã
å°è¯ä¸ä¸
animation: 3s ease-in 1s infinite reverse both running slidein;
animation: 3s linear 1s infinite running slidein;
animation: 3s linear 1s infinite alternate slidein;
animation: 0.5s linear 1s infinite alternate slidein;
<section class="flex-column" id="default-example">
<div id="example-element"></div>
</section>
#example-element {
background-color: #1766aa;
margin: 20px;
border: 5px solid #333;
width: 150px;
height: 150px;
border-radius: 50%;
}
@keyframes slidein {
from {
margin-left: -20%;
}
to {
margin-left: 100%;
}
}
è¯æ³
/* @keyframes duration | easing-function | delay |
iteration-count | direction | fill-mode | play-state | name */
animation: 3s ease-in 1s 2 reverse both paused slidein;
/* @keyframes duration | easing-function | delay | name */
animation: 3s linear 1s slidein;
/* two animations */
animation:
3s linear slidein,
3s ease-out 5s slideout;
animation 屿§ç¨æ¥æå®ä¸ç»æå¤ç»å¨ç»ï¼æ¯ç»ä¹é´ç¨éå·ç¸éã
æ¯ç»å¨ç»è§å®ç屿§å¦ä¸ï¼
-
以ä¸å±æ§åºç° 0 次æ 1 次ï¼
-
animation ç name å¼å¯è½æ¯ï¼noneï¼
<custom-ident>ï¼<string> -
<time>å¯è½ä¼åºç° 0ã1 æ 2 次
æ¯ä¸ªå¨ç»å®ä¹ä¸ç屿§å¼ç顺åºå¾éè¦ï¼å¯ä»¥è¢«è§£æä¸º <time> ç第ä¸ä¸ªå¼è¢«åé
ç»animation-durationï¼ç¬¬äºä¸ªåé
ç» animation-delayã
æ¯ä¸ªå¨ç»å®ä¹ä¸çå¼ç顺åºï¼å¯¹äºåºå animation-name å¼ä¸å
¶ä»å
³é®åä¹å¾éè¦ãè§£ææ¶ï¼å¯¹äºé¤ animation-name ä¹å¤çææçå
³é®åï¼å¿
须被åé¢çç®å䏿²¡ææ¾å°å¼ç屿§ææ¥åãæ¤å¤ï¼å¨åºååæ¶ï¼animation-name ä¸ä»¥åå
¶ä»å±æ§å¼ååºåçæ
åµä¸ï¼å¿
é¡»è¾åºå
¶ä»å±æ§çé»è®¤å¼ã
Values
<single-animation-iteration-count>-
å¨ç»ææ¾ç次æ°ã该å¼å¿ é¡»æ¯
animation-iteration-countå¯ç¨çå¼ä¹ä¸ã <single-animation-direction>-
å¨ç»ææ¾çæ¹åã该å¼å¿ é¡»æ¯
animation-directionå¯ç¨çå¼ä¹ä¸ã <single-animation-fill-mode>-
ç¡®å®å¨ç»å¨æ§è¡ä¹ååä¹åè¿ä¸¤ä¸ªé¶æ®µåºç¨çæ ·å¼ã该å¼å¿ é¡»æ¯
animation-fill-modeå¯ç¨çå¼ä¹ä¸ã <single-animation-play-state>-
ç¡®å®å¨ç»æ¯å¦æ£å¨ææ¾ã该å¼å¿ é¡»æ¯
animation-play-stateä¸å¯ç¨çå¼ä¹ä¸ã
è¯æ³
animation =
<single-animation>#
<single-animation> =
<'animation-duration'> ||
<easing-function> ||
<'animation-delay'> ||
<single-animation-iteration-count> ||
<single-animation-direction> ||
<single-animation-fill-mode> ||
<single-animation-play-state> ||
[ none | <keyframes-name> ] ||
<single-animation-timeline>
<animation-duration> =
[ auto | <time [0s,â]> ]#
<easing-function> =
<linear-easing-function> |
<cubic-bezier-easing-function> |
<step-easing-function>
<animation-delay> =
<time>#
<single-animation-iteration-count> =
infinite |
<number [0,â]>
<single-animation-direction> =
normal |
reverse |
alternate |
alternate-reverse
<single-animation-fill-mode> =
none |
forwards |
backwards |
both
<single-animation-play-state> =
running |
paused
<keyframes-name> =
<custom-ident> |
<string>
<single-animation-timeline> =
auto |
none |
<dashed-ident> |
<scroll()> |
<view()>
<linear-easing-function> =
linear |
<linear()>
<cubic-bezier-easing-function> =
ease |
ease-in |
ease-out |
ease-in-out |
<cubic-bezier()>
<step-easing-function> =
step-start |
step-end |
<steps()>
<scroll()> =
scroll( [ <scroller> || <axis> ]? )
<view()> =
view( [ <axis> || <'view-timeline-inset'> ]? )
<linear()> =
linear( [ <number> && <percentage>{0,2} ]# )
<cubic-bezier()> =
cubic-bezier( [ <number [0,1]> , <number> ]#{2} )
<steps()> =
steps( <integer> , <step-position>? )
<scroller> =
root |
nearest |
self
<axis> =
block |
inline |
x |
y
<view-timeline-inset> =
[ [ auto | <length-percentage> ]{1,2} ]#
<integer> =
<number-token>
<step-position> =
jump-start |
jump-end |
jump-none |
jump-both |
start |
end
<length-percentage> =
<length> |
<percentage>
示ä¾
>èµé人ä¹ç¼
<div class="view_port">
<div class="polling_message">Listening for dispatches</div>
<div class="cylon_eye"></div>
</div>
.polling_message {
color: white;
float: left;
margin-right: 2%;
}
.view_port {
background-color: black;
height: 25px;
width: 100%;
overflow: hidden;
}
.cylon_eye {
background-color: red;
background-image: linear-gradient(
to right,
rgba(0, 0, 0, 0.9) 25%,
rgba(0, 0, 0, 0.1) 50%,
rgba(0, 0, 0, 0.9) 75%
);
color: white;
height: 100%;
width: 20%;
-webkit-animation: 4s linear 0s infinite alternate move_eye;
animation: 4s linear 0s infinite alternate move_eye;
}
@-webkit-keyframes move_eye {
from {
margin-left: -20%;
}
to {
margin-left: 100%;
}
}
@keyframes move_eye {
from {
margin-left: -20%;
}
to {
margin-left: 100%;
}
}
æ´å¤ç¤ºä¾è¯·åé ä½¿ç¨ CSS å¨ç»ã
æ½å¨çé®é¢
ç¨ç¼åéªççå¨ç»å¯¹äºæè®¤ç¥é®é¢ç人æ¥è¯´æ¯æé®é¢çï¼æ¯å¦æ³¨æå缺é·å¤å¨éç¢ (ADHD)ãæ¤å¤ï¼æäºå¨ç»ææå¯ä»¥è§¦åååºç¥ç»ç´ä¹±ãç«ç«ãå头çåæç¹æææ§ã
èèæä¾ä¸ç§æåæç¦ç¨å¨ç»çæºå¶ï¼ä»¥åä½¿ç¨ Reduced Motion Media Queryï¼ç®çº¦è¿å¨åªä½æ¥è¯¢ï¼ï¼ä¸ºé£äºè¡¨ç¤ºä¸å欢å¨ç»çç¨æ·å建ä¸ä¸ªè¯å¥½çä½éªã
è§è
| è§è |
|---|
| CSS Animations Level 1 > # animation > |
æµè§å¨å ¼å®¹æ§
åè§
- Using CSS animations
- JavaScript
AnimationEventAPI