亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(wǎng)
    最全最豐富的資訊網(wǎng)站

    使用css3中的什么規(guī)則來定義動(dòng)畫

    使用css3中的“@keyframes”規(guī)則來定義動(dòng)畫?!癅keyframes”規(guī)則用于指定動(dòng)畫規(guī)則,定義一個(gè)CSS動(dòng)畫的一個(gè)周期的行為,可以創(chuàng)建簡單的動(dòng)畫;可通過沿動(dòng)畫序列建立關(guān)鍵幀來指定動(dòng)畫序列循環(huán)期間的中間步驟。

    使用css3中的什么規(guī)則來定義動(dòng)畫

    本教程操作環(huán)境:windows7系統(tǒng)、CSS3&&HTML5版、Dell G3電腦。

    @keyframes是CSS3的一種規(guī)則,可以用來定義CSS動(dòng)畫的一個(gè)周期的行為,可以創(chuàng)建簡單的動(dòng)畫。

    動(dòng)畫與轉(zhuǎn)換類似,因?yàn)樗鼈兌际请S時(shí)間改變CSS屬性的表示值。主要區(qū)別在于,當(dāng)屬性值更改時(shí)(例如,當(dāng)懸停時(shí)屬性值發(fā)生改變時(shí)),轉(zhuǎn)換會(huì)隱式的觸發(fā),但在應(yīng)用動(dòng)畫屬性時(shí)會(huì)顯式執(zhí)行動(dòng)畫。因此,動(dòng)畫需要顯示動(dòng)畫屬性的顯式值。這些值是在@keyframes規(guī)則中指定的動(dòng)畫關(guān)鍵幀定義的。因此,@keyframes規(guī)則里是由一組封裝的CSS樣式規(guī)則組成的,這些規(guī)則描述了屬性值如何隨時(shí)間變化。

    然后,使用不同的CSS animation(動(dòng)畫)屬性,可以控制動(dòng)畫的許多不同方面,包括動(dòng)畫迭代的次數(shù),是否在開始和結(jié)束值之間交替,以及動(dòng)畫是否應(yīng)該運(yùn)行或暫停。動(dòng)畫也可以延遲其開始時(shí)間。

    @keyframe規(guī)則由關(guān)鍵字“@keyframe”組成,后面接著是給出動(dòng)畫名稱的標(biāo)識(shí)符(將使用animation-name引用),隨后是通過一組樣式規(guī)則(用大括號(hào)分隔)。然后,通過使用標(biāo)識(shí)符作為animation-name屬性的值,將動(dòng)畫應(yīng)用于元素。

    語法:

    @keyframes animation-name {keyframes-selector {css-styles;}}
    • animation-name:這是必需的,它定義動(dòng)畫名稱。

    • keyframes-selector:定義動(dòng)畫的百分比,它介于0%到100%之間。一個(gè)動(dòng)畫可以包含許多選擇器。

    /* 定義動(dòng)畫n */ @keyframes your-animation-name {     /* style rules */ } /* 將其應(yīng)用于元素 */ .element {     animation-name: your-animation-name;     /* 或者使用動(dòng)畫速記屬性 */     animation: your-animation-name 1s ... }

    在大括號(hào)內(nèi),定義關(guān)鍵幀或路徑點(diǎn),這些關(guān)鍵幀或路徑點(diǎn)在動(dòng)畫期間的某些點(diǎn)上指定要設(shè)置動(dòng)畫的屬性的值。這允許您在動(dòng)畫序列中控制中間步驟。例如,一個(gè)簡單的動(dòng)畫@keyframe可能如下所示:

    @keyframes change-bg-color {     0% {         background-color: red;     }     100% {         background-color: blue;     } }

    0%”和“100%”是關(guān)鍵幀選擇器,每個(gè)都定義了關(guān)鍵幀規(guī)則。關(guān)鍵幀規(guī)則的關(guān)鍵幀聲明塊由屬性和值組成。

    還可以使用選擇器關(guān)鍵字from和to,而不是分別使用0%和100%,因?yàn)樗鼈兪堑葍r(jià)的。

    @keyframes change-bg-color {     from {         background-color: red;     }     to {         background-color: blue;     } }

    關(guān)鍵幀選擇器由一個(gè)或多個(gè)逗號(hào)分隔的百分比值或from和to關(guān)鍵字組成。注意,百分比單位說明符必須用于百分比值。因此,' 0 '是一個(gè)無效的關(guān)鍵幀選擇器。(學(xué)習(xí)視頻分享:css視頻教程)

    注意:為了獲得瀏覽器的最佳支持,請(qǐng)始終指定0%和100%選擇器。

    css @keyframes的使用示例:

    1、定義動(dòng)畫發(fā)生的空間

    HTML代碼:

    <div class="container">   <div class="element"></div> </div>

    2、使用@keyframes規(guī)則創(chuàng)建簡單動(dòng)畫

    css代碼

    body {   background-color: #fff;   color: #555;   font-size: 1.1em;   font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; } .container {   margin: 50px auto;   min-width: 320px;   max-width: 500px; }  .element {   margin: 0 auto;   width: 100px;   height: 100px;   background-color: #0099cc;   border-radius: 50%;   position: relative;   top: 0;   -webkit-animation: bounce 2s infinite;   animation: bounce 2s infinite; }  @-webkit-keyframes bounce {   from {     top: 100px;     -webkit-animation-timing-function: ease-out;     animation-timing-function: ease-out;   }   25% {     top: 50px;     -webkit-animation-timing-function: ease-in;     animation-timing-function: ease-in;   }   50% {     top: 150px;     -webkit-animation-timing-function: ease-out;     animation-timing-function: ease-out;   }   75% {     top: 75px;     -webkit-animation-timing-function: ease-in;     animation-timing-function: ease-in;   }   to {     top: 100px;   } }  @keyframes bounce {   from {     top: 100px;     -webkit-animation-timing-function: ease-out;     animation-timing-function: ease-out;   }   25% {     top: 50px;     -webkit-animation-timing-function: ease-in;     animation-timing-function: ease-in;   }   50% {     top: 150px;     -webkit-animation-timing-function: ease-out;     animation-timing-function: ease-out;   }   75% {     top: 75px;     -webkit-animation-timing-function: ease-in;     animation-timing-function: ease-in;   }   to {     top: 100px;   } }

    3、運(yùn)行效果

    使用css3中的什么規(guī)則來定義動(dòng)畫

    贊(0)
    分享到: 更多 (0)
    網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)