css3設(shè)置動(dòng)畫(huà)的4個(gè)相關(guān)屬性:1、transform屬性,用于向元素應(yīng)用2D或3D轉(zhuǎn)換;2、transition屬性,用于實(shí)現(xiàn)過(guò)渡效果;3、animation屬性,用于給元素綁定動(dòng)畫(huà);4、“@keyframes”,定義動(dòng)畫(huà)一個(gè)周期的行為。
本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。
css3動(dòng)畫(huà)的屬性總的來(lái)說(shuō)只有transform(變形),transition(過(guò)渡),和animation(動(dòng)畫(huà))這三種。
transform
屬性向元素應(yīng)用 2D 或 3D 轉(zhuǎn)換。該屬性允許我們對(duì)元素進(jìn)行旋轉(zhuǎn)、縮放、移動(dòng)或傾斜。
transition
屬性是一個(gè)簡(jiǎn)寫(xiě)屬性,用于設(shè)置四個(gè)過(guò)渡屬性:
-
transition-property
-
transition-duration
-
transition-timing-function
-
transition-delay
animation
屬性是一個(gè)簡(jiǎn)寫(xiě)屬性,用于設(shè)置六個(gè)動(dòng)畫(huà)屬性:
-
animation-name
-
animation-duration
-
animation-timing-function
-
animation-delay
-
animation-iteration-count
-
animation-direction
animation 屬性需要和@keyframes規(guī)則一起使用,才可創(chuàng)建動(dòng)畫(huà)。
@keyframes
規(guī)則
通過(guò) @keyframes 規(guī)則,您能夠創(chuàng)建動(dòng)畫(huà)。
創(chuàng)建動(dòng)畫(huà)的原理是,將一套 CSS 樣式逐漸變化為另一套樣式。
在動(dòng)畫(huà)過(guò)程中,您能夠多次改變這套 CSS 樣式。
以百分比來(lái)規(guī)定改變發(fā)生的時(shí)間,或者通過(guò)關(guān)鍵詞 "from" 和 "to",等價(jià)于 0% 和 100%。
0% 是動(dòng)畫(huà)的開(kāi)始時(shí)間,100% 動(dòng)畫(huà)的結(jié)束時(shí)間。
為了獲得最佳的瀏覽器支持,您應(yīng)該始終定義 0% 和 100% 選擇器。
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <style> div { width: 100px; height: 100px; background: red; position: relative; animation: mymove 5s infinite; -webkit-animation: mymove 5s infinite; /* Safari and Chrome */ } @keyframes mymove { 0% { top: 0px; left: 0px; background: red; } 25% { top: 0px; left: 100px; background: blue; } 50% { top: 100px; left: 100px; background: yellow; } 75% { top: 100px; left: 0px; background: green; } 100% { top: 0px; left: 0px; background: red; } } @-webkit-keyframes mymove /* Safari and Chrome */ { 0% { top: 0px; left: 0px; background: red; } 25% { top: 0px; left: 100px; background: blue; } 50% { top: 100px; left: 100px; background: yellow; } 75% { top: 100px; left: 0px; background: green; } 100% { top: 0px; left: 0px; background: red; } } </style> </head> <body> <div></div> </body> </html>
(學(xué)習(xí)視頻分享:css視頻教程)