CSS3動畫以及animation事件

來源:互聯網
上載者:User

標籤:播放   blog   結束   一個   等於   css3動畫   microsoft   名稱   soft   

1、CSS3動畫以及animation事件的定義 animation  :name duration timing-function delay iteration-count directionanimation-name:動畫名稱    animation-name:keyframename|none(keyframename:自訂名字 none:動畫無效果)animation-duration:動畫執行時間   animation-duration:time(time:秒/毫秒)animation-timing-function:動畫速度曲線 【animation-timing-function:value;linnear:規定以相同速度開始至結束的過渡效果(等於 cubic-bezier(0,0,1,1))ease:規定以慢速開始的過渡效果(等於 cubic-bezier(0.25,0.1,0.25,1))ease-in:規定以慢速開始的過渡效果(等於 cubic-bezier(0.42,0,1,1))ease-out:規定以慢速結束的過渡效果(等於 cubic-bezier(0,0,0.58,1))ease-in-out:規定以慢速開始和結束的過渡效果(等於 cubic-bezier(0.42,0,0.58,1))cubic-bezier(n,n,n,n):在cubic-bezier函數中定義自己的值,可能的數值在0~1之間steps(n):階躍函數】animation-delay:動畫效果延遲時間  animation-delay:time(time:秒/毫秒)animation-iteration-count:動畫執行次數  animation-iteration-count:n|infinite(n:具體次數 、infinite:無限重複)animation-direction:動畫執行方向   animation-direction:normal|alternate(normal:動畫順序播放、alternate:動畫輪流反向播放)animation-play-state:動畫執行狀態     animation-play-state:pause | running(paused:暫停動畫、running:運行動畫)animation-fill-mode:動畫執行過程效果是否可見 

animation-fill-mode:none | forwards | backwards | both (none:不改變[預設值]、forwards:當動畫完成後,保持最後一個屬性值[在最後一個主要畫面格中定義]) 、backwords:在animation所指定的一段時間內,在動畫顯示前,應運開始屬性值(在第一個主要畫面格中定義)、both:向前後相後填充模式都被應用

@keyframes:規定動畫 @keyframes animationname {keyframes-selector{css-styles;}}

keyframes-selector :動畫時間長度百分比0~100%from(與0%相同)to(與100%相同)可以只有一個tocss-styles:一個或者多個合法的css樣式屬性

動畫事件:動畫開始:obj.addEventListener("webkitAnimationStart",fn);//Chrome瀏覽器安全色模式     obj.addEventListener("animationstart",fn);//其他相容瀏覽器動畫執行過程中觸發:     obj.addEventListener("webkitAnimationIteration",fn);     obj.addEventListener("animationIteration",fn);動畫結束後觸發:     obj.addEventListener("webkitAnimationEnd",fn);     obj.addEventListener("animationEnd",fn);2、CSS3動畫以及animation事件應用範例程式碼<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>animation事件</title>
<style>
*{
margin:0;
padding: 0;
}
div{
width: 100px;
height: 300px;
background: #666;
animation: anim 2s 1s linear 3 alternate forwards ;/*第一個time是動畫改變的1時間,第二個是開始之前的延時*/
}
@keyframes anim {
0%{width: 50px;}
100%{width: 300px;}
}
</style>
</head>
<body>
<div id="div"></div>
<script>
var oDiv = document.getElementById("div");
oDiv.addEventListener("webkitAnimationStart",start);
oDiv.addEventListener("animationStart",start);
oDiv.addEventListener("webkitAnimationIteration",iteration);
oDiv.addEventListener("animationIteration",iteration);
oDiv.addEventListener("webkitAnimationEnd",end);
oDiv.addEventListener("animationEnd",end);
function start() {
oDiv.style.background = "red";
}
function iteration() {
oDiv.style.background = "green";
}
function end() {
oDiv.style.background = "blue";
}
</script>
</body>
</html>3、樣本

樣本源碼:animation事件.zip轉載請註明出處,謝謝您的合作! 

CSS3動畫以及animation事件

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.