隨著CSS3越來越熱,CSS3動畫也逐漸受到大家的關注
以下是自己的一點理解,希望能對大家有所幫助。
…
## 淘寶案例解析

需求:鼠標移動到菜單上時旋轉箭頭,且給支持CSS3的瀏覽器加上旋轉動畫。
源碼請查看demo源文件。
demo ([http://fiddle.jshell.net/pjRVT/show/light/](http://fiddle.jshell.net/pjRVT/show/light/))
…
## 關于CSS3動畫
從([http://www.w3.org/Style/CSS/current-work](http://www.w3.org/Style/CSS/current-work))可以看出,CSS動畫涉及的知識點包括 CSS 2D Transformations, CSS 3D Transformations, CSS Transitions, CSS Animations。
Transformation 補充定義了width, height, left, top等之外的一些可用于實現動畫的屬性,如rotate, scale, skew。
Transition 和 Animation 用于定義動畫的過程。其中Transition 可以實現簡單的動畫;Animation則可以通過設定多個關鍵幀實現相對復雜的動畫。
…
## Can I Use? 兼容性
(數據來自[http://caniuse.com/](http://caniuse.com/))
<table style="border: 1px solid #ccc" cellspacing="3">
<tbody>
<tr style="background: #f2f2f2">
<th width="140"> </th>
<th width="40">IE</th>
<th width="60">Firefox</th>
<th width="80">Safari</th>
<th width="60">Chrome</th>
<th width="60">Opera</th>
</tr>
<tr>
<td style="font-weight: bold">CSS 2D Transform</td>
<td style="color:red">no</td>
<td>3.5</td>
<td>3.2</td>
<td>2.0</td>
<td>10.5</td>
</tr>
<tr>
<td style="font-weight: bold">CSS 3D Transform</td>
<td style="color:red">no</td>
<td style="color:red">no</td>
<td>4.* (Mac)</td>
<td style="color:red">no</td>
<td style="color:red">no</td>
</tr>
<tr>
<td style="font-weight: bold">CSS Transition</td>
<td style="color:red">no</td>
<td>3.7</td>
<td>3.2</td>
<td>2.0</td>
<td>10.5</td>
</tr>
<tr>
<td style="font-weight: bold">CSS Animation</td>
<td style="color:red">no</td>
<td style="color:red">no</td>
<td>4.0</td>
<td>2.0</td>
<td style="color:red">no</td>
</tr>
</tbody>
</table>
<span id="more-1969"></span>
可以看到,CSS Animation目前只有Webkit內核瀏覽器支持,目前只能自己玩玩;而Transition用來做漸進增強則較為合適。
…
## 一個簡單的例子
需求:讓一個div元素在鼠標移上去時變大1倍,旋轉180度,且背景由紅變藍。
html code::
<div></div>
`</pre>
css code::
<pre>`div {
position: absolute;
left: 100px;
top: 100px;
width: 100px;
height: 100px;
background: red;
/* 定義動畫的過程 */
-webkit-transition: -webkit-transform .5s ease-in, background .5s ease-in;
-moz-transition: -moz-transform .5s ease-in, background .5s ease-in;
-o-transition: -o-transform .5s ease-in, background .5s ease-in;
transition: transform .5s ease-in, background .5s ease-in;
}
div:hover {
/* 定義動畫的狀態 */
-webkit-transform: rotate(180deg) scale(2);
-moz-transform: rotate(180deg) scale(2);
-o-transform: rotate(180deg) scale(2);
-transform: rotate(180deg) scale(2);
background: blue;
}
demo ([http://fiddle.jshell.net/NVErB/show/light/](http://fiddle.jshell.net/NVErB/show/light/)) (no IE)
…
## 無奈的瀏覽器前綴
這是個令人非常痛苦的問題,因為不得不針對每個瀏覽器copy一遍重復代碼。
值得注意的是無前綴的標準代碼需放在最后。假如幾年后某個屬性成為標準,被瀏覽器默認支持了,這行代碼會覆蓋前面的定義,使得瀏覽器可以優先使用他。
…
## 稍微復雜點的例子(css3 animation)
需求:讓一個div元素在點擊后變大1倍,旋轉180度,且背景由紅變藍;然后向右移動400px。
源碼請查看demo源文件。
demo ([http://fiddle.jshell.net/a4r94/show/light/](http://fiddle.jshell.net/a4r94/show/light/)) (Safari, Chrome only)
…
## 驚艷!CSS 3D Transformations
見live demo ([http://www.satine.org/research/webkit/snowleopard/snowstack.html](http://www.satine.org/research/webkit/snowleopard/snowstack.html)) (Mac Safari Only,類似于http://www.cooliris.com/的效果),沒Mac的可以到(h[ttp://www.satine.org/archives/2009/07/11/snow-stack-is-here/](//www.satine.org/archives/2009/07/11/snow-stack-is-here/))看視頻演示。
PS: Mac Safari的3D Transform、2D Transform和Opacity等視覺效果都是跑在GPU上的,為此我還特地驗證下了Win Safari,果然不支持。
…
## 相關資料
**webkit blog介紹animation/2d transforms/3d transforms的三篇文章**
[http://webkit.org/blog/138/css-animation/](http://webkit.org/blog/138/css-animation/)
[http://webkit.org/blog/130/css-transforms/](http://webkit.org/blog/130/css-transforms/)
[http://webkit.org/blog/386/3d-transforms/](http://webkit.org/blog/386/3d-transforms/)
**W3組織的CSS規范集**
[http://www.w3.org/Style/CSS/current-work](http://www.w3.org/Style/CSS/current-work)
**蘋果官方關于CSS視覺效果的文檔**
[http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Introduction/Introduction.html](http://developer.apple.com/safari/library/documentation/InternetWeb/Conceptual/SafariVisualEffectsProgGuide/Introduction/Introduction.html)
**css animation的兼容性數據來源**
[http://caniuse.com/](http://caniuse.com/)
**3d transform的運用app**
[http://www.satine.org/research/webkit/snowleopard/snowstack.html](http://www.satine.org/research/webkit/snowleopard/snowstack.html)
[http://css-vfx.googlecode.com/svn/trunk/examples/zflow.html](http://css-vfx.googlecode.com/svn/trunk/examples/zflow.html)
[http://www.fofronline.com/experiments/cube-3d/](http://www.fofronline.com/experiments/cube-3d/)
**css3動畫的應用**
[http://www.webdesignerwall.com/trends/47-amazing-css3-animation-demos/](http://www.webdesignerwall.com/trends/47-amazing-css3-animation-demos/)
[http://www.optimum7.com/internet-marketing/web-development/pure-css3-spiderman-ipad-cartoon-jquery-html5-no-flash.html](http://www.optimum7.com/internet-marketing/web-development/pure-css3-spiderman-ipad-cartoon-jquery-html5-no-flash.html)
[http://www.optimum7.com/css3-man/animation.html](http://www.optimum7.com/css3-man/animation.html)
[http://hedgerwow.appspot.com/demo/flippage](http://hedgerwow.appspot.com/demo/flippage)
[http://neography.com/journal/our-solar-system-in-css3/](http://neography.com/journal/our-solar-system-in-css3/)
[http://css-tricks.com/examples/StarryNightCSS3/](http://css-tricks.com/examples/StarryNightCSS3/)
[http://www.dmxzone.com/demo/dmxAnimator/effects/slide_out_menu.html](http://www.dmxzone.com/demo/dmxAnimator/effects/slide_out_menu.html)
**css3 animation的入門應用:鐘的實現**
[http://g-zone.org/test/g-clock/index.html](http://g-zone.org/test/g-clock/index.html)
…
完
- 前端篇
- 常用知識點
- 表單處理
- 前后端分離
- 提供模板渲染工具
- 頁面優化
- css3動畫部分
- 前端工程與模塊化框架
- 服務器XML標簽用法
- 微信JSSDK
- 小技巧
- 純CSS實現自適應正方形
- 通用媒體查詢
- css 黑科技
- H5性能優化方案
- 10個最常見的 HTML5
- 常見坑
- 資源收集
- 前端組件化開發實踐
- 應用秒開計劃
- AJAX API部分
- 靜態資源處理優化
- 后端篇
- 微信對接與管理
- 微信消息處理
- API插件開發
- Plugin開發
- 后端插件開發
- 組件開發
- XML標簽開發
- RESTFUL設計
- Admin GUI
- 設計篇
- 設計規范
- 微信開發庫v.js
- 使用方法
- 微信JSSDK集成
- 調試面板使用
- 插件-http功能
- 插件-layer彈出層
- 插件-music 音樂播放器
- 插件-store 本地存儲
- 插件 emitter 事件管理器
- 插件-shake 搖動功能
- 插件-lazyload 延遲加載
- 插件-t 模板渲染
- 插件-ani 動畫功能
- 插件-is 類型偵測器
- 插件-ease 緩動函數庫
- 插件-os 設備檢測
- 插件 $ 類Jquery插件
- 插件-md5 散列計算
- 插件-svg動畫loading
- 后臺頁面成功GUI
- 列表渲染List
- 表單生成Config
- 樹狀列表Tree
- 排序操作Sort
- Js 風格指南
- Vuep
- 內置動畫庫
- 組件庫
- 內置插件庫
- PSD自動切圖