offset-distance CSS property specifies a position along an offset-path for an element to be placed.

句法

/* Default value */
offset-distance: 0;
/* the middle of the offset-path */
offset-distance: 50%;
/* a fixed length positioned along the path */
offset-distance: 40px;
					
<length-percentage>
A length that specifies how far the element is along the path (defined with offset-path ).
100% represents the total length of the path (when the offset-path is defined as a basic shape or path() ).

形式定义

初始值 0
适用于 transformable elements
继承 no
百分比 refer to the total path length
计算值 for <length> the absolute value, otherwise a percentage
动画类型 a length , percentage or calc();

形式句法

<length-percentage>

where
<length-percentage> = <length> | <percentage>

范例

Using offset-distance in an animation

The motion aspect in CSS Motion Path typically comes from animating the offset-distance property. If you want to animate an element along its full path, you would define its offset-path and then set up an animation that takes the offset-distance from 0% to 100% .

HTML

<div id="motion-demo"></div>
					

CSS

#motion-demo {
  offset-path: path('M20,20 C20,100 200,0 200,100');
  animation: move 3000ms infinite alternate ease-in-out;
  width: 40px;
  height: 40px;
  background: cyan;
}
@keyframes move {
  0% {
    offset-distance: 0%;
  }
  100% {
    offset-distance: 100%;
  }
}
					

结果

规范

规范 状态 注释
Motion Path Module Level 1
The definition of 'offset-distance' in that specification.
工作草案 初始定义

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
offset-distance Chrome 完整支持 55
完整支持 55
完整支持 46 Alternate Name
Alternate Name Uses the non-standard name: motion-distance
Edge 完整支持 79
完整支持 79
完整支持 79 Alternate Name
Alternate Name Uses the non-standard name: motion-distance
Firefox 完整支持 72
完整支持 72
不支持 69 — 72 Disabled
Disabled ). To change preferences in Firefox, visit
IE 不支持 No Opera 完整支持 42
完整支持 42
完整支持 33 Alternate Name
Alternate Name Uses the non-standard name: motion-distance
Safari 不支持 No WebView Android 完整支持 55
完整支持 55
完整支持 46 Alternate Name
Alternate Name Uses the non-standard name: motion-distance
Chrome Android 完整支持 55
完整支持 55
完整支持 46 Alternate Name
Alternate Name Uses the non-standard name: motion-distance
Firefox Android 不支持 No Opera Android 完整支持 42
完整支持 42
完整支持 33 Alternate Name
Alternate Name Uses the non-standard name: motion-distance
Safari iOS 不支持 No Samsung Internet Android 完整支持 6.0
完整支持 6.0
完整支持 5.0 Alternate Name
Alternate Name Uses the non-standard name: motion-distance

图例

完整支持

完整支持

不支持

不支持

用户必须明确启用此特征。

用户必须明确启用此特征。

使用非标名称。

使用非标名称。

元数据

  • 最后修改:
  1. CSS
  2. CSS 参考
  3. CSS Motion Path
  4. 特性
    1. offset
    2. offset-anchor
    3. offset-distance
    4. offset-path
    5. offset-position
    6. offset-rotate

Copyright  © 2014-2026 乐数软件    

工业和信息化部: 粤ICP备14079481号-1