rotate
rotate
属性指定了在 <animateMotion>
元素中定义的路径上移动时,动画元素的旋转方式。
你可以将此属性与以下 SVG 元素一起使用
用法说明
值 |
auto | auto-reverse | <number> |
---|---|
默认值 | 0 |
可动画的 | 否 |
auto
和 auto-reverse
值允许动画元素的旋转在其沿着路径移动时动态改变。如果 rotate
的值为 auto
,元素会转向使其右侧对准当前的运动方向。如果值为 auto-reverse
,则会转向使其左侧对准当前的运动方向。
将 rotate
的值设置为一个数字,表示一个恒定的旋转角度(以度为单位),这个角度不会随着动画而改变。默认值 0
保持动画元素的原始方向。
示例
SVG
html
<svg
width="400"
height="120"
viewBox="0 0 480 120"
xmlns="http://www.w3.org/2000/svg">
<!-- Draw the outline of the motion path in grey -->
<path
d="M10,110 A120,120 -45 0,1 110 10 A120,120 -45 0,1 10,110"
stroke="lightgrey"
stroke-width="2"
fill="none"
id="theMotionPath" />
<!-- Red arrow which will not rotate -->
<path fill="red" d="M-5,-5 L10,0 -5,5 0,0 Z">
<!-- Define the motion path animation -->
<animateMotion dur="6s" repeatCount="indefinite" rotate="0">
<mpath href="#theMotionPath" />
</animateMotion>
</path>
<g transform="translate(100, 0)">
<use href="#theMotionPath" />
<!-- Green arrow which will rotate along the motion path -->
<path fill="green" d="M-5,-5 L10,0 -5,5 0,0 Z">
<!-- Define the motion path animation -->
<animateMotion dur="6s" repeatCount="indefinite" rotate="auto">
<mpath href="#theMotionPath" />
</animateMotion>
</path>
</g>
<g transform="translate(200, 0)">
<use href="#theMotionPath" />
<!-- Blue arrow which will rotate backwards along the motion path -->
<path fill="blue" d="M-5,-5 L10,0 -5,5 0,0 Z">
<!-- Define the motion path animation -->
<animateMotion dur="6s" repeatCount="indefinite" rotate="auto-reverse">
<mpath href="#theMotionPath" />
</animateMotion>
</path>
</g>
<g transform="translate(300, 0)">
<use href="#theMotionPath" />
<!-- Purple arrow which will have a static rotation of 210 degrees -->
<path fill="purple" d="M-5,-5 L10,0 -5,5 0,0 Z">
<!-- Define the motion path animation -->
<animateMotion dur="6s" repeatCount="indefinite" rotate="210">
<mpath href="#theMotionPath" />
</animateMotion>
</path>
</g>
</svg>
结果
规范
此特性似乎未在任何规范中定义。浏览器兼容性
加载中…