
- CSS 教程
- CSS - 首頁
- CSS - 路線圖
- CSS - 簡介
- CSS - 語法
- CSS - 選擇器
- CSS - 包含
- CSS - 測量單位
- CSS - 顏色
- CSS - 背景
- CSS - 字型
- CSS - 文字
- CSS - 圖片
- CSS - 連結
- CSS - 表格
- CSS - 邊框
- CSS - 塊級邊框
- CSS - 內聯邊框
- CSS - 外邊距
- CSS - 列表
- CSS - 內邊距
- CSS - 游標
- CSS - 輪廓
- CSS - 尺寸
- CSS - 捲軸
- CSS - 塊內元素
- CSS - 下拉選單
- CSS - 可見性
- CSS - 溢位
- CSS - Clearfix
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 排序
- CSS - 定位
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 位移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z-Index
- CSS - 底部
- CSS - 導航欄
- CSS - 疊加層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根元素
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪裁
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - All
- CSS - 內嵌
- CSS - 隔離
- CSS - 滾動溢位
- CSS - Justify Items
- CSS - Justify Self
- CSS - Tab Size
- CSS - 指標事件
- CSS - Place Content
- CSS - Place Items
- CSS - Place Self
- CSS - 最大塊級尺寸
- CSS - 最小塊級尺寸
- CSS - 混合模式
- CSS - 最大內聯尺寸
- CSS - 最小內聯尺寸
- CSS - 偏移
- CSS - 重音色
- CSS - 使用者選擇
- CSS 高階
- CSS - 網格
- CSS - 網格佈局
- CSS - Flexbox
- CSS - 可見性
- CSS - 定位
- CSS - 層
- CSS - 偽類
- CSS - 偽元素
- CSS - @規則
- CSS - 文字效果
- CSS - 分頁媒體
- CSS - 列印
- CSS - 佈局
- CSS - 驗證
- CSS - 圖片精靈
- CSS - !important
- CSS - 資料型別
- CSS3 教程
- CSS3 - 教程
- CSS - 圓角
- CSS - 邊框圖片
- CSS - 多重背景
- CSS - 顏色
- CSS - 漸變
- CSS - 盒陰影
- CSS - 盒裝飾中斷
- CSS - 游標顏色
- CSS - 文字陰影
- CSS - 文字
- CSS - 2D 變換
- CSS - 3D 變換
- CSS - 過渡
- CSS - 動畫
- CSS - 多列
- CSS - 盒尺寸
- CSS - 工具提示
- CSS - 按鈕
- CSS - 分頁
- CSS - 變數
- CSS - 媒體查詢
- CSS - 函式
- CSS - 數學函式
- CSS - 遮罩
- CSS - 形狀
- CSS - 樣式圖片
- CSS - 特效性
- CSS - 自定義屬性
- CSS 響應式
- CSS RWD - 簡介
- CSS RWD - 視口
- CSS RWD - 網格檢視
- CSS RWD - 媒體查詢
- CSS RWD - 圖片
- CSS RWD - 影片
- CSS RWD - 框架
- CSS 工具
- CSS - PX 到 EM 轉換器
- CSS - 顏色選擇器和動畫
- CSS 資源
- CSS - 有用資源
- CSS - 討論
CSS - animation-timing-function 屬性
CSS animation-timing-function 屬性決定動畫的速度曲線,它決定動畫從一組 CSS 樣式過渡到另一組 CSS 樣式所花費的時間。它決定了動畫的節奏。
語法
animation-timing-function: linear | ease | ease-in | ease-out | ease-in-out | step-start | step-end | steps(int, start | end) | cubic-bezier(n, n, n, n) | initial | inherit;
屬性值
值 | 描述 |
---|---|
linear | 動畫從開始到結束速度相同。 |
ease | 動畫開始緩慢,然後加速,然後再次減速。預設值。 |
ease-in | 動畫開始緩慢,然後加速。 |
ease-out | 動畫正常播放,但在結束時減速。 |
ease-in-out | 動畫開始緩慢,然後加速,然後再次減速。 |
step-start | 動畫在關鍵幀動畫開始時直接跳轉到結束狀態。 |
step-end | 動畫在關鍵幀動畫結束時跳轉到結束狀態。 |
steps(int,start|end) | 它指定一個步進函式,其中包含步驟數以及開始或結束位置(例如,steps(6, end))。 |
cubic-bezier(n,n,n,n) | 它使用三次貝塞爾曲線定義自定義計時函式(例如,cubic-bezier(0.25, 0.1, 0.25, 1.0))。可能的值為 0 到 1。 |
initial | 它將屬性設定為其預設值。 |
inherit | 它從其父元素繼承屬性。 |
CSS 動畫計時函式屬性示例
以下示例使用不同的值和函式解釋了animation-timing-function屬性。
設定動畫始終保持相同速度
為了讓動畫從開始到結束保持相同的速度,我們使用linear值。在下面的示例中,linear 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> h3 { width: 200px; text-align: center; animation-name: text; animation-duration: 4s; animation-iteration-count: infinite; border: 2px solid black; } #linear { animation-timing-function: linear; } @keyframes text { from { margin-left: 35%; } to { margin-left: 0%; } } </style> </head> <body> <h2>CSS animation-timing-function property </h2> <h3 id="linear">Linear value</h3> </body> </html>
為動畫設定緩慢的開始和結束
為了讓動畫開始緩慢,然後加速,然後再次減速,我們使用ease值。在下面的示例中,ease 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> h3 { width: 200px; text-align: center; animation-name: text; animation-duration: 4s; animation-iteration-count: infinite; border: 2px solid black; } #linear { animation-timing-function: ease; } @keyframes text { from { margin-left: 35%; } to { margin-left: 0%; } } </style> </head> <body> <h2>CSS animation-timing-function property </h2> <h3 id="linear">Ease value</h3> </body> </html>
為動畫設定緩慢的開始
為了讓動畫開始緩慢然後加速,我們使用ease-in值。在下面的示例中,ease-in 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> h3 { width: 200px; text-align: center; animation-name: text; animation-duration: 4s; animation-iteration-count: infinite; border: 2px solid black; } #linear { animation-timing-function: ease-in; } @keyframes text { from { margin-left: 35%; } to { margin-left: 0%; } } </style> </head> <body> <h2>CSS animation-timing-function property </h2> <h3 id="linear">Ease-in value</h3> </body> </html>
為動畫設定緩慢的結束
為了讓動畫以正常速度播放,但在結束時減速,我們使用ease-out值。在下面的示例中,ease-out 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> h3 { width: 200px; text-align: center; animation-name: text; animation-duration: 4s; animation-iteration-count: infinite; border: 2px solid black; } #linear { animation-timing-function: ease-out; } @keyframes text { from { margin-left: 35%; } to { margin-left: 0%; } } </style> </head> <body> <h2>CSS animation-timing-function property </h2> <h3 id="linear">Ease-out value</h3> </body> </html>
為動畫設定緩慢的開始和結束
為了讓動畫開始緩慢,然後加快速度,然後在結束時減速,我們還可以使用 ease-in 和 ease-out 值的組合,即ease-in-out值。在下面的示例中,ease-in-out 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> h3 { width: 200px; text-align: center; animation-name: text; animation-duration: 4s; animation-iteration-count: infinite; border: 2px solid black; } #linear { animation-timing-function: ease-in-out; } @keyframes text { from { margin-left: 35%; } to { margin-left: 0%; } } </style> </head> <body> <h2>CSS animation-timing-function property </h2> <h3 id="linear">Ease-in-out value</h3> </body> </html>
設定從開始時的突然跳轉
為了讓動畫在動畫的關鍵幀開始時直接到達結束狀態,從而導致突然變化,我們使用step-start值。在下面的示例中,step-start 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> .box { width: 100px; height: 50px; border: 2px solid black; display: flex; justify-content: center; animation: move 6s infinite; } .step-start { animation-timing-function: step-start; } @keyframes move { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(250px); } } </style> </head> <body> <h2>CSS animation-timing-function property</h2> <div class="box step-start">Step-start</div> </body> </html>
設定從結束時的突然跳轉
為了讓動畫在動畫的關鍵幀結束時直接到達結束狀態,從而導致突然變化,我們使用step-end值。在下面的示例中,step-end 值已用於 animation-timing-function 屬性。
示例
<!DOCTYPE html> <html> <head> <style> .box { width: 100px; height: 50px; border: 2px solid black; display: flex; justify-content: center; animation: move 6s infinite; } .step-start { animation-timing-function: step-end; } @keyframes move { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(250px); } } </style> </head> <body> <h2>CSS animation-timing-function property</h2> <div class="box step-start">Step-end</div> </body> </html>
設定分步動畫
為了讓動畫以分步間隔移動,我們使用steps()函式。它接受兩個引數,第一個是整數,第二個是“start”或“end”,指定值在間隔內發生變化的點。在下面的示例中,整數為 4,第二個引數為 start。
示例
<!DOCTYPE html> <html> <head> <style> .box { width: 100px; height: 50px; border: 2px solid black; display: flex; justify-content: center; animation: move 6s infinite; } .step-start { animation-timing-function: steps(4,start); } @keyframes move { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(250px); } } </style> </head> <body> <h2>CSS animation-timing-function property</h2> <div class="box step-start">Steps(4,start)</div> </body> </html>
設定可變速度動畫
為了讓動畫以可變速度進行,我們使用cubic-bezier()函式。此函式表示三次貝塞爾曲線,它由四個點 P0、P1、P2、P3 定義:P0(開始)和 P3(結束)。在下面的示例中,函式中使用了 0.1、0.7、1.0 和 0.1 值。
示例
<!DOCTYPE html> <html> <head> <style> .box { width: 100px; height: 50px; border: 2px solid black; display: flex; justify-content: center; align-items: center; animation: move 6s infinite; } .cubic { animation-timing-function: cubic-bezier(0.1, 0.7, 1.0, 0.1); } @keyframes move { 0%,100% { transform: translateX(0); } 50% { transform: translateX(250px); } } </style> </head> <body> <h2>CSS animation-timing-function property</h2> <div class="box cubic">Cubic Beizer</div> </body> </html>
支援的瀏覽器
屬性 | ![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|---|
animation-timing-function | 43.0 | 10.0 | 16.0 | 9.0 | 30.0 |