<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="ARTICLE @ XOOPS powered by FeedCreator" -->
<feed version="0.3" xmlns="http://purl.org/atom/ns#" xml:lang="zh-TW">
    <title>睡蓮‧池水間 :: 文章</title>
    <tagline>文章XML</tagline>
    <link rel="alternate" type="text/html" href="http://waterlily-lsl.com/modules/article/view.article.php/223/c2"/>
    <id>http://waterlily-lsl.com/modules/article/view.article.php/223/c2</id>
    <modified>2012-02-11T03:00:34+02:00</modified>
    <author>
        <name>waterlily at waterlily-lsl dot com</name>
    </author>
    <generator>ARTICLE @ XOOPS powered by FeedCreator</generator>
    <entry>
        <title>使用 CSS3 創建動畫效果</title>
        <link rel="alternate" type="text/html" href="http://waterlily-lsl.com/modules/article/view.article.php/223/c2"/>
        <created>2010-02-01T14:36:14+02:00</created>
        <issued>2010-02-01T14:36:14+02:00</issued>
        <modified>2010-02-01T14:36:14+02:00</modified>
        <id>http://waterlily-lsl.com/modules/article/view.article.php/223/c2</id>
        <author>
            <name>睡蓮</name>
        </author>
        <summary>類別: 語言集&lt;br /&gt;來源: (http://wlsy.me/1740/)&lt;h3 id=&quot;heading1&quot;&gt;&lt;span style=&quot;text-decoration:underline&quot;&gt;概述&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;在 CSS3 中新增了幾個很好玩的東東：CSS Animation，CSS Transition 和 CSS Transform，顧名思義就是通過 CSS 來實現動畫，過渡和變形。&lt;br /&gt;&lt;br /&gt;它們與 HTML5 中的 canvas 能繪製動畫圖形不同，這些只能應用在已存在的元素上，但這足以讓我很興奮了，我不必要在去寫那些複雜的 JS 代碼，運用它們我能更簡單的創建自己的想要的動畫。&lt;br /&gt;&lt;br /&gt;&lt;h3 id=&quot;heading2&quot;&gt;&lt;span style=&quot;text-decoration:underline&quot;&gt;應用前景&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;伴隨著 CSS3 的普及，這些特性被各大瀏覽器支持也只是時間上的問題。有消息稱在 Internet Explorer 9 中將更好的支持 HTML5 和 CSS3。所以各位圍觀群眾不必擔心這只是曇花一現。以下是我就目前的瀏覽器支持狀態統計的一個表格：&lt;br /&gt;&lt;table class=&quot;artContable3&quot;&gt;&lt;tr&gt;&lt;th&gt;&lt;/th&gt;&lt;th&gt;　　　IE8 -　　　&lt;/th&gt;&lt;th&gt;chrome &amp;amp; safair&lt;/th&gt;&lt;th&gt;firefox 3.5.5 *(3)&lt;/th&gt;&lt;th&gt;opera 10.10- *(4)&lt;/th&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;CSS Transiton&lt;/th&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;O&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;CSS Animation&lt;/th&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;O&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;2D Transform&lt;/th&gt;&lt;td&gt;*(1)&lt;/td&gt;&lt;td&gt;O&lt;/td&gt;&lt;td&gt;O&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;th&gt;3D Transform&lt;/th&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;*(2)&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;td&gt;X&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;br /&gt;&lt;strong class=&quot;A_strong&quot;&gt;備註：&lt;/strong&gt;&lt;br /&gt;*(1)：IE 可以通過濾鏡來實現部分變形&lt;br /&gt;*(2) : Windows 下的 chrome 和 safair 支持部分 3D Transform。mac 和 iphone 下的 safair 支持全部 3D Transform (未驗證)&lt;br /&gt;*(3)：firefox3.7 同 IE9 一樣稱將支持更多 CSS3 特性，不過最終是否支持 Animation 和 3D Transform 還不是很確定&lt;br /&gt;*(4)：oprea 已經在表示在 Presto2.3(opera 內核)中將支持 Transtion。可查看 wiki&lt;br /&gt;&lt;br /&gt;接下來要開始了，各位看官準備好 chrome 或 safair，演示和代碼使用 webkit 的私有屬性，let's 幹吧。&lt;br /&gt;&lt;br /&gt;&lt;h3 id=&quot;heading3&quot;&gt;&lt;span style=&quot;text-decoration:underline&quot;&gt;CSS Transition&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;這個能實現很舒服的過度效果，先看CSS代碼片段：&lt;br /&gt;&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;.box {
width: 200px;
height: 200px;
background: #ccc;
-webkit-transition: all 1s ease-in-out; /*實現 hover 狀態是 backround 的過渡*/
}
.box:hover {
background: #333;
}&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;你可以在&lt;a href=&quot;http://www.g9net.com/wp-content/uploads/2009/12/ani1.html&quot; rel=&quot;external&quot;&gt;這裡&lt;/a&gt;看到這個演示，務必請用基於 webkit 的 chrome 或 safair（以下同）。看完演示是不是很有興趣想去學如何去使用了？transiton 屬性有這幾個值：&lt;br /&gt;&lt;br /&gt;transition-property :* //指定過度的性質，比如 transition-property：backgrond 就是只指定 backgound 參與這個過渡&lt;br /&gt;&lt;br /&gt;transition-duration:*//指定這個過渡的持續時間&lt;br /&gt;&lt;br /&gt;transition-delay:* //延遲過渡時間&lt;br /&gt;&lt;br /&gt;transition-timing-function:*//指定過度類型，有 ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier&lt;br /&gt;&lt;div class=&quot;xoopsQuote&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/Quote-icon.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;div&gt;&lt;strong class=&quot;A_strong&quot;&gt;小貼士&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;linear //線性過度&lt;br /&gt;ease-in //由慢到快&lt;br /&gt;ease-out //由快到慢&lt;br /&gt;ease-in-out //由慢到快在到慢&lt;br /&gt;&lt;br /&gt;timing-funciton 的幾種過度類型都是基於 cubic-bezier 的某些特定數值。比如 ease-in-out 的類型它也可以寫成 cubic-bezier(0.42, 0, 0.58, 1.0)。你可以在&lt;a href=&quot;http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag&quot; rel=&quot;external&quot;&gt;這裡&lt;/a&gt;看到 cubic-bezier 曲線圖&lt;br /&gt;&lt;br /&gt;Transiton 和下面的 Animation 都是支持 CSS 偽類&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;同樣的，這些我們可以簡寫，拿上面的代碼 -webkit-transition: all 1s ease-in-out; 包含了property , duration ,timing-fuction。&lt;br /&gt;&lt;br /&gt;&lt;strong class=&quot;A_strong&quot;&gt;參考資料：&lt;/strong&gt;&lt;br /&gt;&lt;a href=&quot;http://www.w3.org/TR/css3-transitions/#transition-timing-function_tag&quot; rel=&quot;external&quot;&gt;CSS Transitions Module Level 3&lt;/a&gt; （這個是w3c的官方文檔，英語好的可以詳細看看）&lt;br /&gt;&lt;a href=&quot;http://webkit.org/blog/138/css-animation/&quot; title=&quot;http://webkit.org/blog/138/css-animation/&quot; rel=&quot;external&quot;&gt;http://webkit.org/blog/138/css-animation/&lt;/a&gt; （這個webkit官方博客上的講解，也有例子）&lt;br /&gt;&lt;br /&gt;怎麼樣，趕緊打開編輯器自己寫寫吧&lt;br /&gt;&lt;br /&gt;&lt;h3 id=&quot;heading4&quot;&gt;&lt;span style=&quot;text-decoration:underline&quot;&gt;CSS Animation&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;顧名思義，這個就能實現元素的動畫效果，那時我就被震驚了，無數次那尼感嘆。可以先看下&lt;a href=&quot;http://www.g9net.com/wp-content/uploads/2009/12/ani2.html&quot; rel=&quot;external&quot;&gt;演示&lt;/a&gt;，代碼如下&lt;br /&gt;&lt;div class=&quot;xoopsCode&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon1.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;pre&gt;
@-webkit-keyframes title {
0% {
text-shadow:0px 0px 15px #000;
}
50% {
text-shadow: 0px 0px 30px #3995bd;
color: #aac7d4;
margin-top:200px;
}
100% {
text-shadow: 0px 0px 15px #000;
}
}
h1 {
-webkit-animation: title infinite ease-in-out 3s;
}
&lt;/pre&gt;&lt;/div&gt;&lt;br /&gt;&lt;strong class=&quot;A_strong&quot;&gt;animation 有這幾個屬性：&lt;/strong&gt;&lt;br /&gt;animation-name//屬性名，就是我們定義的 keyframes&lt;br /&gt;animation-duration //持續時間&lt;br /&gt;animation-timing-function //同上面的 transition-timing-function&lt;br /&gt;animation-delay // 設置動畫延遲&lt;br /&gt;animation-iteration-count //定義循環次數，infinite 為無限&lt;br /&gt;animation-direction //定義動畫方式&lt;br /&gt;&lt;br /&gt;這些同樣是可以簡寫的。但真正讓我覺的很爽的是 keyframes 這個似乎有點像 js 裡面的 function，它能定義一個動畫的轉變過程供調用，過程為 0% 到 100% 或 from(0%) 到 to(100%) ，簡單點說，只要你有想法，你想讓元素在這個過程中以什麼樣的方式改變都是很簡單的。&lt;br /&gt;&lt;br /&gt;你是不是已經開始蠢蠢欲動了？&lt;br /&gt;&lt;br /&gt;&lt;strong class=&quot;A_strong&quot;&gt;參考資料：&lt;/strong&gt;&lt;br /&gt;&lt;a href=&quot;http://www.w3.org/TR/2009/WD-css3-animations-20090320/&quot; title=&quot;http://www.w3.org/TR/2009/WD-css3-animations-20090320/&quot; rel=&quot;external&quot;&gt;http://www.w3.org/TR/2009/WD-css3-animations-20090320/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;h3 id=&quot;heading5&quot;&gt;&lt;span style=&quot;text-decoration:underline&quot;&gt;Transform&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;transform 就是實現元素的變形，為什麼放到最後？如果跟上面的 CSS Animation 結合起來是不是更酷呢？先看看這樣一個&lt;a href=&quot;http://www.g9net.com/wp-content/uploads/2009/12/ani3.html&quot; rel=&quot;external&quot;&gt;演示&lt;/a&gt;，相信你不敢相信這只用 CSS 寫出來的效果吧。&lt;br /&gt;&lt;br /&gt;&lt;strong class=&quot;A_strong&quot;&gt;transform 有幾種類型：&lt;/strong&gt;&lt;br /&gt;scale(num,num) //尺寸，scale(2,3)即 x 軸方向放大兩倍，y 軸方向放大3被，同樣的可單獨寫 scaleX(2),scaleY(3)&lt;br /&gt;&lt;br /&gt;rotate(*deg) //旋轉的角度&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;xoopsQuote&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/Quote-icon.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;div&gt;在2d transform 中旋轉角度俺當前的平面順時針或逆時針旋轉。在 3d transform 中新增了 rotateX 和 rotateY 它們分別以 y 軸或 x 軸為中心進行旋轉，同樣可以簡寫稱 rotate(*,*)。目前已被chrome和safair支持&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;skew（*deg）//傾斜角度，同樣的有 skewX 和 skewY 可簡寫為 skew（*,*）&lt;br /&gt;&lt;br /&gt;translate //移動&lt;br /&gt;&lt;br /&gt;&lt;div class=&quot;xoopsQuote&quot;&gt;&lt;p class=&quot;cTitle&quot;&gt;&lt;img class=&quot;icon-l&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/Quote-icon.gif&quot; alt=&quot;&quot;/&gt;&lt;img class=&quot;icon-r&quot; src=&quot;http://waterlily-lsl.com/themes/waterlilyLSL-GW/img/code-icon2.gif&quot; alt=&quot;&quot;/&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;div&gt;在 2d transform 中分為 translateX 和translateY 簡而言之就是元素網x軸或y軸的移動距離，而在 3dtransform 中新增了一個 translateZ 及實現Z軸的移動，實現透視效果。目前在 Windows 系統上還沒有瀏覽器支持，同樣的這些可以簡寫。&lt;br /&gt;&lt;/div&gt;&lt;/blockquote&gt;&lt;/div&gt;&lt;br /&gt;了解完這些用法後在去看看那個演示的源碼，相信你肯定會驚嘆 transform 和 animation 配合的動畫效果了吧 &lt;br /&gt;&lt;br /&gt;&lt;strong class=&quot;A_strong&quot;&gt;參考資料：&lt;/strong&gt; &lt;br /&gt;&lt;a href=&quot;http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/&quot; title=&quot;http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/&quot; rel=&quot;external&quot;&gt;http://www.w3.org/TR/2009/WD-css3-2d-transforms-20090320/&lt;/a&gt; （w3c文檔） &lt;br /&gt;&lt;a href=&quot;http://webkit.org/blog/386/3d-transforms/&quot; rel=&quot;external&quot;&gt;3D Transforms&lt;/a&gt; （webkit博客上的文章，所以在Windows下沒法看到，不過那裡有截圖過過癮，並有一個很酷在Windows下打了折扣的&lt;a href=&quot;http://webkit.org/blog-files/3d-transforms/morphing-cubes.html&quot; rel=&quot;external&quot;&gt;demo&lt;/a&gt;哦） &lt;br /&gt;&lt;a href=&quot;http://www.zachstronaut.com/lab/isocube.html&quot; title=&quot;http://www.zachstronaut.com/lab/isocube.html&quot; rel=&quot;external&quot;&gt;http://www.zachstronaut.com/lab/isocube.html&lt;/a&gt;(這個就是用transfrom實現的立方體) &lt;br /&gt;&lt;br /&gt;&lt;h3 id=&quot;heading6&quot;&gt;&lt;span style=&quot;text-decoration:underline&quot;&gt;結語&lt;/span&gt;&lt;/h3&gt;&lt;br /&gt;看到這些，你是否跟我一樣期待 HTML5 和 CSS3 的快點普及呢？在運用這些新特性能快速而簡單的創建原本需要復雜js來實現的動畫效果，這是多麼讓人興奮的。 &lt;br /&gt;&lt;br /&gt;不過這些還是有那麼些缺點的，CSS Animation 的確很酷，但不得不提及它的資源佔用問題，CSS transform 的確很神奇，但不得不提及它的鋸齒問題，當然了這些問題相信瀏覽器的開發者會逐漸改善的。&lt;br /&gt;</summary>
    </entry>
</feed>

