CSS3 animation
定义keyframes
@keyframes colorchange { 0% { background-color: #00F; /* from: blue */ } 25% { background-color: #F00; /* red */ } 50% { background-color: #0F0; /* green */ } 75% { background-color: #F0F; /* purple */ } 100% { background-color: #00F; /* to: blue */ } } @-webkit-keyframes colorchange { 0% { background-color: #00F; /* from: blue */ } 25% { background-color: #F00; /* red */ } 50% { background-color: #0F0; /* green */ } 75% { background-color: #F0F; /* purple */ } 100% { background-color: #00F; /* to: blue */ } }
对于0%这个也可以用from关键字来替代,同样的可以用to来代替100%,过渡状态,你可以定义任何百分比;
将animation应用到元素的属性写法,和transition差不太多:
div:hover { animation-name: colorchange; animation-duration: 1s; animation-timing-function: linear; animation-delay: 1s; animation-fill-mode:forwards; /*forwards表示让动画停留在结束状态*/ animation-direction: normal; animation-iteration-count: 3; /*用来指定动画循环的次数,无限循环用infinite*/ } /****简写****/ div:hover { animation: 1s 1s rainbow linear 3 forwards normal; }
animation-direction有四个值:
normal:默认,从0%执行到100%
reverse:动画从100%执行到0%
alternate:动画在0%到100%之间往复执行;
alternate-reverse与alternate一致,不过是从100%开始;
animation-play-state
有时,动画播放过程中,会突然停止。这时,默认行为是跳回到动画的开始状态;
如果想让动画保持突然终止时的状态可以使用animation-play-state: running;
浏览器支持
IE 10和Firefox(>= 16)支持没有前缀的animation,而chrome不支持,所以必须使用webkit前缀。
也就是说,实际运用中,代码必须写成下面的样子:
div:hover { -webkit-animation: 1s rainbow; animation: 1s rainbow; } @-webkit-keyframes rainbow { 0% { background: #c00; } 50% { background: orange; } 100% { background: yellowgreen; } } @keyframes rainbow { 0% { background: #c00; } 50% { background: orange; } 100% { background: yellowgreen; } }
参考资料:
http://www.zhangxinxu.com/wordpress/2010/11/css3-transitions-transforms-animation-introduction/
http://www.w3cplus.com/content/css3-transform
http://beiyuu.com/css3-animation/
http://www.zhangxinxu.com/wordpress/2012/06/css3-transform-matrix-%E7%9F%A9%E9%98%B5/
http://www.ruanyifeng.com/blog/2014/02/css_transition_and_animation.html

本文討論了HTML< Progress>元素,其目的,樣式和與< meter>元素。主要重點是使用< progress>為了完成任務和LT;儀表>對於stati

本文討論了html< datalist>元素,通過提供自動完整建議,改善用戶體驗並減少錯誤來增強表格。Character計數:159

本文討論了HTML< meter>元素,用於在一個範圍內顯示標量或分數值及其在Web開發中的常見應用。它區分了< meter>從< progress>和前

本文討論了視口元標籤,這對於移動設備上的響應式Web設計至關重要。它解釋瞭如何正確使用確保最佳的內容縮放和用戶交互,而濫用可能會導致設計和可訪問性問題。

本文解釋了HTML5< time>語義日期/時間表示的元素。 它強調了DateTime屬性對機器可讀性(ISO 8601格式)的重要性,並在人類可讀文本旁邊,增強Accessibilit

本文討論了使用HTML5表單驗證屬性,例如必需的,圖案,最小,最大和長度限制,以直接在瀏覽器中驗證用戶輸入。

本文討論了< iframe>將外部內容嵌入網頁,其常見用途,安全風險以及諸如對象標籤和API等替代方案的目的。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

SAP NetWeaver Server Adapter for Eclipse
將Eclipse與SAP NetWeaver應用伺服器整合。

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

Dreamweaver CS6
視覺化網頁開發工具

WebStorm Mac版
好用的JavaScript開發工具