数值
通过传递 Number
或至少包含一个 Number
的 String
来指定动画属性的数值。
如果对于期望单位的属性(例如 width
)未指定单位,则生成的动画将使用默认浏览器单位。
animate(target, { width: 100 }); // Defaults to px
接受
数字
字符串
如果已指定特定单位,则 JS animate()
方法可以继承先前定义的单位,并且在同一目标属性上设置的下一个没有单位的值将继承先前定义的单位。
animate(target, { width: '50%' }); // Uses '%'
animate(target, { width: 75 }); // Inherits '%' -> '75%'
WAAPI animate()
方法仅对以下属性自动回退到 'px'
- x / translateX
- y / translateY
- z / translateZ
- perspective
- top
- right
- bottom
- left
- width
- height
- margin
- padding
- borderWidth
- borderRadius
- fontSize
数值代码示例
import { waapi } from 'animejs';
waapi.animate('.square', {
x: 240, // -> 240px
width: 75, // -> 75px
rotate: '.75turn',
});
<div class="large row">
<div class="square"></div>
</div>