transition: ;
/* 簡寫多屬性 */
transition: top 0.5s ease, left 0.5s ease;
/* 或分開寫 */
transition-property: top, left;
transition-duration: 0.5s, 0.5s;
transition-timing-function: ease, ease;
| 值 | 描述 | 典型場景 |
|---|---|---|
| ease | 緩慢開始,緩慢結束(默認) | 通用自然過渡 |
| linear | 勻速 | 機械線性移動 |
| ease-in | 緩慢開始 | 元素進場 |
| ease-out | 緩慢結束 | 元素離場 |
| ease-in-out | 緩慢開始並結束 | 強調平滑感 |
<style>
#box {
width: 200px; height: 200px; background: chocolate;
position: relative; left: 0; top: 0;
transition: top 5s ease, left 5s ease;
/* 廠商前綴 -moz-, -webkit-, -o- 略 */
}
</style>
<div id="box"></div>
<button id="e1">ease</button>
<button id="e2">linear</button> ...
<script>
box.style.transitionTimingFunction = "ease"; // 動態修改曲線
box.style.left = "1000px"; box.style.top = "100px"; // 觸發過渡
</script>
animation: name duration timing-function delay iteration-count direction;
/* 關鍵幀定義 */
@keyframes mymove {
from { top: 0px; }
50% { top: 200px; }
to { top: 0px; }
}
| 屬性 | 說明 |
|---|---|
| animation-name | 綁定的 @keyframes 名稱 |
| animation-duration | 一個週期耗時(秒/毫秒) |
| animation-timing-function | 速度曲線(同 transition) |
| animation-delay | 開始前延遲 |
| animation-iteration-count | 播放次數(數字或 infinite) |
| animation-direction | normal / reverse / alternate / alternate-reverse |
div {
width: 100px; height: 100px; background: red;
position: relative;
animation: mymove 5s infinite;
}
@keyframes mymove {
from { top: 0px; }
to { top: 200px; }
}
.scene {
perspective: 800px; /* 視點距離屏幕距離 */
perspective-origin: 50% 50%; /* 視點位置(屏幕中心) */
transform-style: preserve-3d; /* 子元素保持 3D 空間 */
transform-origin: 0% 100%; /* 旋轉中心點(此處為左下角) */
}

| 類型 | 函數 | 示例 |
|---|---|---|
| 位移 | translateX(x) | transform: translateX(500px) |
| translateY(y) | transform: translateY(400px) | |
| translateZ(z) | transform: translateZ(200px) | |
| 旋轉 | rotateX(deg) | 繞 X 軸旋轉(向屏幕上邊向內為正) |
| rotateY(deg) | 繞 Y 軸旋轉(向屏幕右側向內為正) | |
| rotateZ(deg) | 繞 Z 軸旋轉(向屏幕外為正,同 2D rotate) |

left | center | righttop | center | bottom<length>(像素值)默認中心為元素幾何中心。示例中設為 0% 100%(左下角),配合 rotateY 實現翻書效果。
<style>
#box { width:200px; height:200px; background:chocolate; position:relative;
perspective:800px; perspective-origin:50% 50%; transform-style:preserve-3d;
transform-origin:0% 100%; }
</style>
<div id="box"></div>
<button id="rx">rotateX</button>
<button id="ry">rotateY</button>
<button id="rz">rotateZ</button>
<script>
rx.onclick = () => box.style.transform = "rotateX(30deg)";
ry.onclick = () => box.style.transform = "rotateY(30deg)";
rz.onclick = () => box.style.transform = "rotateZ(30deg)";
</script>
transform、opacity(GPU 加速),避免 top/left/width/height 觸發重排。will-change: transform)。@supports 檢測特性,提供無動畫備選樣式。prefers-reduced-motion 媒體查詢,為敏感用戶禁用動畫。原文地址:CSS3 動畫效果小結