单位转换值

转换并动画到与默认或当前使用的不同单位的值。

在使用 JS animate()方法时,根据所使用的单位类型和动画属性,单位转换有时可能会产生意想不到的结果。
为了获得更可预测的结果,建议在动画之外使用 utils.set()定义单位,然后再动画到当前单位。

或者直接使用 WAAPI animate()方法。

接受

字符串

单位转换值代码示例

import { animate, utils } from 'animejs';

animate('.square', {
  width: '25%', // from '48px' to '25%',
  x: '15rem', // from '0px' to '15rem',
  rotate: '.75turn', // from `0deg` to '.75turn',
});
<div class="large row">
  <div class="square"></div>
</div>