degToRad() V4
将度数转换为弧度。
const radians = utils.degToRad(degrees);
参数
名称 | 接受 |
---|---|
度数 (可选) | 数字 |
返回
如果提供了度数,则为 Number
类型,否则为 可链式工具 Function
,用于将度数转换为弧度
const degToRad = utils.degToRad();
degToRad(360); // 6.283185307179586
const roundDegToRad = utils.degToRad().round(2); // Convert degrees to radians then round to 2 decimal places
roundDegToRad(180); // 3.14
roundDegToRad(90); // 1.57
degToRad() 代码示例
import { animate, createAnimatable, utils } from 'animejs';
const radAnimatable = createAnimatable('.rad', {
rotate: { unit: 'rad', duration: 0 },
});
const [ $deg ] = utils.$('.deg');
const degAnimation = animate($deg, {
rotate: '360deg',
ease: 'linear',
loop: true,
onUpdate: () => {
const degrees = utils.get($deg, 'rotate', false);
radAnimatable.rotate(utils.degToRad(degrees));
}
});
<div class="x-large spaced-evenly row">
<div class="col">
<div class="clock deg"></div>
<div class="label">degrees</div>
</div>
<div class="col">
<div class="clock rad"></div>
<div class="label">radians</div>
</div>
</div>