CSS3 ¶¯»
CSS3 ¶¯»
ͨ¹ý CSS3£¬ÎÒÃÇÄܹ»´´½¨¶¯»£¬Õâ¿ÉÒÔÔÚÐí¶àÍøÒ³ÖÐÈ¡´ú¶¯»Í¼Æ¬¡¢Flash ¶¯»ÒÔ¼° JavaScript¡£
CSS3 ¶¯»
CSS3 @keyframes ¹æÔò
ÈçÐèÔÚ CSS3 Öд´½¨¶¯»£¬ÄúÐèҪѧϰ @keyframes ¹æÔò¡£
@keyframes ¹æÔòÓÃÓÚ´´½¨¶¯»¡£ÔÚ @keyframes Öй涨ijÏî CSS Ñùʽ£¬¾ÍÄÜ´´½¨Óɵ±Ç°ÑùʽÖ𽥸ÄΪÐÂÑùʽµÄ¶¯»Ð§¹û¡£
ä¯ÀÀÆ÷Ö§³Ö
ÊôÐÔ | ä¯ÀÀÆ÷Ö§³Ö | ||||
---|---|---|---|---|---|
@keyframes | |||||
animation |
Internet Explorer 10¡¢Firefox ÒÔ¼° Opera Ö§³Ö @keyframes ¹æÔòºÍ animation ÊôÐÔ¡£
Chrome ºÍ Safari ÐèҪǰ׺ -webkit-¡£
×¢ÊÍ£ºInternet Explorer 9£¬ÒÔ¼°¸üÔçµÄ°æ±¾£¬²»Ö§³Ö @keyframe ¹æÔò»ò animation ÊôÐÔ¡£
ʵÀý
@keyframes myfirst { from {background: red;} to {background: yellow;} } @-moz-keyframes myfirst /* Firefox */ { from {background: red;} to {background: yellow;} } @-webkit-keyframes myfirst /* Safari ºÍ Chrome */ { from {background: red;} to {background: yellow;} } @-o-keyframes myfirst /* Opera */ { from {background: red;} to {background: yellow;} }
CSS3 ¶¯»
µ±ÄúÔÚ @keyframes Öд´½¨¶¯»Ê±£¬Çë°ÑËüÀ¦°óµ½Ä³¸öÑ¡ÔñÆ÷£¬·ñÔò²»»á²úÉú¶¯»Ð§¹û¡£
ͨ¹ý¹æ¶¨ÖÁÉÙÒÔÏÂÁ½Ïî CSS3 ¶¯»ÊôÐÔ£¬¼´¿É½«¶¯»°ó¶¨µ½Ñ¡ÔñÆ÷£º
- ¹æ¶¨¶¯»µÄÃû³Æ
- ¹æ¶¨¶¯»µÄʱ³¤
ʵÀý
°Ñ "myfirst" ¶¯»À¦°óµ½ div ÔªËØ£¬Ê±³¤£º5 Ã룺
div { animation: myfirst 5s; -moz-animation: myfirst 5s; /* Firefox */ -webkit-animation: myfirst 5s; /* Safari ºÍ Chrome */ -o-animation: myfirst 5s; /* Opera */ }
×¢ÊÍ£ºÄú±ØÐ붨Ò嶯»µÄÃû³ÆºÍʱ³¤¡£Èç¹ûºöÂÔʱ³¤£¬Ôò¶¯»²»»áÔÊÐí£¬ÒòΪĬÈÏÖµÊÇ 0¡£
ʲôÊÇ CSS3 Öе͝»£¿
¶¯»ÊÇÊ¹ÔªËØ´ÓÒ»ÖÖÑùʽÖ𽥱仯ΪÁíÒ»ÖÖÑùʽµÄЧ¹û¡£
Äú¿ÉÒԸıäÈÎÒâ¶àµÄÑùʽÈÎÒâ¶àµÄ´ÎÊý¡£
ÇëÓðٷֱÈÀ´¹æ¶¨±ä»¯·¢ÉúµÄʱ¼ä£¬»òÓùؼü´Ê "from" ºÍ "to"£¬µÈͬÓÚ 0% ºÍ 100%¡£
0% ÊǶ¯»µÄ¿ªÊ¼£¬100% ÊǶ¯»µÄÍê³É¡£
ΪÁ˵õ½×î¼ÑµÄä¯ÀÀÆ÷Ö§³Ö£¬ÄúÓ¦¸ÃʼÖÕ¶¨Òå 0% ºÍ 100% Ñ¡ÔñÆ÷¡£
ʵÀý
µ±¶¯»Îª 25% ¼° 50% ʱ¸Ä±ä±³¾°É«£¬È»ºóµ±¶¯» 100% Íê³ÉʱÔٴθı䣺
@keyframes myfirst { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-moz-keyframes myfirst /* Firefox */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-webkit-keyframes myfirst /* Safari ºÍ Chrome */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} } @-o-keyframes myfirst /* Opera */ { 0% {background: red;} 25% {background: yellow;} 50% {background: blue;} 100% {background: green;} }
ʵÀý
¸Ä±ä±³¾°É«ºÍλÖãº
@keyframes myfirst { 0% {background: red; left:0px; top:0px;} 25% {background: yellow; left:200px; top:0px;} 50% {background: blue; left:200px; top:200px;} 75% {background: green; left:0px; top:200px;} 100% {background: red; left:0px; top:0px;} } @-moz-keyframes myfirst /* Firefox */ { 0% {background: red; left:0px; top:0px;} 25% {background: yellow; left:200px; top:0px;} 50% {background: blue; left:200px; top:200px;} 75% {background: green; left:0px; top:200px;} 100% {background: red; left:0px; top:0px;} } @-webkit-keyframes myfirst /* Safari ºÍ Chrome */ { 0% {background: red; left:0px; top:0px;} 25% {background: yellow; left:200px; top:0px;} 50% {background: blue; left:200px; top:200px;} 75% {background: green; left:0px; top:200px;} 100% {background: red; left:0px; top:0px;} } @-o-keyframes myfirst /* Opera */ { 0% {background: red; left:0px; top:0px;} 25% {background: yellow; left:200px; top:0px;} 50% {background: blue; left:200px; top:200px;} 75% {background: green; left:0px; top:200px;} 100% {background: red; left:0px; top:0px;} }
CSS3 ¶¯»ÊôÐÔ
ÏÂÃæµÄ±í¸ñÁгöÁË @keyframes ¹æÔòºÍËùÓж¯»ÊôÐÔ£º
ÊôÐÔ | ÃèÊö | CSS |
---|---|---|
@keyframes | ¹æ¶¨¶¯»¡£ | 3 |
animation | ËùÓж¯»ÊôÐԵļòдÊôÐÔ£¬³ýÁË animation-play-state ÊôÐÔ¡£ | 3 |
animation-name | ¹æ¶¨ @keyframes ¶¯»µÄÃû³Æ¡£ | 3 |
animation-duration | ¹æ¶¨¶¯»Íê³ÉÒ»¸öÖÜÆÚËù»¨·ÑµÄÃë»òºÁÃ롣ĬÈÏÊÇ 0¡£ | 3 |
animation-timing-function | ¹æ¶¨¶¯»µÄËÙ¶ÈÇúÏß¡£Ä¬ÈÏÊÇ "ease"¡£ | 3 |
animation-delay | ¹æ¶¨¶¯»ºÎʱ¿ªÊ¼¡£Ä¬ÈÏÊÇ 0¡£ | 3 |
animation-iteration-count | ¹æ¶¨¶¯»±»²¥·ÅµÄ´ÎÊý¡£Ä¬ÈÏÊÇ 1¡£ | 3 |
animation-direction | ¹æ¶¨¶¯»ÊÇ·ñÔÚÏÂÒ»ÖÜÆÚÄæÏòµØ²¥·Å¡£Ä¬ÈÏÊÇ "normal"¡£ | 3 |
animation-play-state | ¹æ¶¨¶¯»ÊÇ·ñÕýÔÚÔËÐлòÔÝÍ£¡£Ä¬ÈÏÊÇ "running"¡£ | 3 |
animation-fill-mode | ¹æ¶¨¶ÔÏ󶯻ʱ¼äÖ®ÍâµÄ״̬¡£ | 3 |
ÏÂÃæµÄÁ½¸öÀý×ÓÉèÖÃÁËËùÓж¯»ÊôÐÔ£º
ʵÀý
ÔËÐÐÃûΪ myfirst µÄ¶¯»£¬ÆäÖÐÉèÖÃÁËËùÓж¯»ÊôÐÔ£º
div { animation-name: myfirst; animation-duration: 5s; animation-timing-function: linear; animation-delay: 2s; animation-iteration-count: infinite; animation-direction: alternate; animation-play-state: running; /* Firefox: */ -moz-animation-name: myfirst; -moz-animation-duration: 5s; -moz-animation-timing-function: linear; -moz-animation-delay: 2s; -moz-animation-iteration-count: infinite; -moz-animation-direction: alternate; -moz-animation-play-state: running; /* Safari ºÍ Chrome: */ -webkit-animation-name: myfirst; -webkit-animation-duration: 5s; -webkit-animation-timing-function: linear; -webkit-animation-delay: 2s; -webkit-animation-iteration-count: infinite; -webkit-animation-direction: alternate; -webkit-animation-play-state: running; /* Opera: */ -o-animation-name: myfirst; -o-animation-duration: 5s; -o-animation-timing-function: linear; -o-animation-delay: 2s; -o-animation-iteration-count: infinite; -o-animation-direction: alternate; -o-animation-play-state: running; }
ʵÀý
ÓëÉÏÃæµÄ¶¯»Ïàͬ£¬µ«ÊÇʹÓÃÁ˼òдµÄ¶¯» animation ÊôÐÔ£º
div { animation: myfirst 5s linear 2s infinite alternate; /* Firefox: */ -moz-animation: myfirst 5s linear 2s infinite alternate; /* Safari ºÍ Chrome: */ -webkit-animation: myfirst 5s linear 2s infinite alternate; /* Opera: */ -o-animation: myfirst 5s linear 2s infinite alternate; }