- 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 - 清除浮動
- CSS - 浮動
- CSS - 箭頭
- CSS - 調整大小
- CSS - 引號
- CSS - 順序
- CSS - 位置
- CSS - 連字元
- CSS - 懸停
- CSS - 顯示
- CSS - 聚焦
- CSS - 縮放
- CSS - 平移
- CSS - 高度
- CSS - 連字元字元
- CSS - 寬度
- CSS - 不透明度
- CSS - Z 索引
- CSS - 底部
- CSS - 導航欄
- CSS - 覆蓋層
- CSS - 表單
- CSS - 對齊
- CSS - 圖示
- CSS - 圖片庫
- CSS - 註釋
- CSS - 載入器
- CSS - 屬性選擇器
- CSS - 組合器
- CSS - 根
- CSS - 盒模型
- CSS - 計數器
- CSS - 剪輯
- CSS - 書寫模式
- CSS - Unicode-bidi
- CSS - min-content
- CSS - 全部
- 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 - 重要
- 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 - offset-path 屬性
offset-path CSS 屬性指定元素在其父容器或 SVG 座標系內的路徑。
該路徑可能是一條線、曲線或其他形狀,它決定了元素沿著該路徑的位置或移動。
offset-path 屬性用於控制元素沿給定路徑的位置和方向,以及 offset-distance、offset-rotate 和 offset-anchor。
offset-path 屬性定義了一個動畫元素可以跟隨的路徑,可以是具有子路徑的指定路徑或基本形狀。
它確定元素的確切位置,包括初始位置和方向。以前稱為 motion-path,現在它描述靜態位置。
可能的值
offset-path 屬性可以接受諸如 offset-path、<coord-box> 或兩者兼而有之的值;它還可以接受關鍵字 none。一個 <url>、一個 <basic-shape> 或一個 ray() 函式可能是 offset-path 的值。
none - none 值表示沒有 offset-path 的元素,它基於其預設位置屬性(如 top 和 left),而不是 offset-path。
<offset-path> - 可以使用 ray() 函式、<url> 值或 <basic-shape> 值來指定 offset-path 屬性。
ray() - ray() 函式建立一個具有固定起始位置、長度和角度的線。
url() - SVG 形狀元素可以透過其 ID 在 url() 函式中被 offset-path 屬性引用。
<basic-shape> - 使用 CSS 基本形狀函式,如 circle()、ellipse()、inset()、path()、polygon()、rect() 或 xywh() 來設定 offset-path 屬性。
<coord-box> - offset-path 屬性包含一個名為 <coord-box> 的可選引數。<coord-box> 定義的 offset path 由參考框大小決定,通常是 SVG 中的 view-box 或 CSS 中的 border-box。
應用於
可變換元素
語法
offset-path = none | <offset-path> || <coord-box>
CSS offset-path - 使用 url()
以下示例演示瞭如何使用 url() 建立 offset-path。
<html>
<head>
<style>
body {
background: #edbb5f;
padding: 90px;
display: flex;
justify-content: center;
}
.track {
stroke: #f0e9e9;
fill: none;
stroke-width: 0.15;
}
.marker {
motion-path: path('M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0');
offset-path: path('M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0');
animation: move 3s linear infinite;
fill: #f23c35;
}
@keyframes move {
100% {
motion-offset: 80%;
offset-distance: 80%;
}
}
</style>
</head>
<body>
<svg viewBox="0,0 10,10" width="300px" height="300px">
<path class="track" d="M 5 5 m -4, 0 a 4,4 0 1,0 8,0 a 4,4 0 1,0 -8,0"/>
<circle class="marker" r="1"></circle>
</svg>
</body>
</html>
CSS offset-path - 使用 path()
以下示例演示瞭如何使用 path() 建立 offset-path。
<html>
<head>
<style>
body {
background: #cfc7c6;
padding: 20px;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.demoOffset {
width: 300px;
height: 300px;
position: relative;
}
.track {
fill: none;
stroke: #1f1e1e;
stroke-width: 2;
}
.object-container {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
clip-path: url(#clip);
}
.object {
width: 50px;
height: 35px;
background-color: #4CAF50;
position: absolute;
offset-path: path("M 10,10 L 290,10 L 290,290 L 10,290 Z");
offset-distance: 100%;
offset-rotate: auto;
animation: move 4s linear infinite;
}
.object:nth-child(2) {
background-color: #FFC107;
animation-delay: -0.3s;
}
.object:nth-child(3) {
background-color: #2196F3;
animation-delay: -1s;
}
.object:nth-child(4) {
background-color: #f2514b;
animation-delay: -1.3s;
}
@keyframes move {
100% {
offset-distance: 0%;
}
}
</style>
</head>
<body>
<div class="demoOffset">
<svg viewBox="0 0 300 300" width="300" height="300" class="track">
<defs>
<clipPath id="clip">
<path d="M 10,10 L 290,10 L 290,290 L 10,290 Z" />
</clipPath>
</defs>
<path d="M 10,10 L 290,10 L 290,290 L 10,290 Z" />
</svg>
<div class="object-container">
<div class="object"></div>
<div class="object"></div>
<div class="object"></div>
<div class="object"></div>
</div>
</div>
</body>
</html>