数值
通过传递一个 Number 或包含至少一个 Number 的 String 来指定动画属性的数值。
如果没有为期望单位的属性指定单位,例如width,则生成的动画将使用浏览器的默认单位。
animate(target, { width: 100 }); // Defaults to px
接受
NumberString
如果已经指定了特定的单位, JS animate() 方法可以继承之前定义的单位,并且在同一目标属性上没有单位设置的下一个值会继承之前定义的单位。
animate(target, { width: '50%' }); // Uses '%'
animate(target, { width: 75 }); // Inherits '%' -> '75%'
The 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>