lerp() V4
根据给定的进度(progress)在两个数字之间插值,或者创建一个具有预定义起始(start)和结束(end)参数的插值函数(Function)。
const interpolatedValue = utils.lerp(start, end, progress);
const interpolatorFunction = utils.lerp(start, end);
参数
| 名称 | 接受 |
|---|---|
| 开始 | 数字 |
| 结束(end) | 数字 |
| 进度(progress) (可选) | 数字(Number) ([0 - 1]) |
返回
如果提供了进度值,则返回一个数字(Number);否则,返回一个用于在指定的起始(start)和结束(end)值之间进行插值的可链式工具函数(Function)
const interpolateBetween0and100 = utils.lerp(0, 100);
interpolateBetween0and100(0.5); // 50
interpolateBetween0and100(0.75); // 75
interpolateBetween0and100(0.25); // 25
const interpolateAndRound = utils.lerp(0, 100).round(2); // Interpolate then round to 2 decimal places
interpolateAndRound(0.677523); // 67.75
interpolateAndRound(1.202514); // 100 lerp() 代码示例
import { animate, utils } from 'animejs';
animate('.normal', {
rotate: '1turn',
duration: 3000,
loop: true,
ease: 'inOut',
});
animate('.interpolated', {
rotate: '1turn',
modifier: utils.lerp(0, 12), // Interpolates 0 to 12 by passing the rotate progress value 0 to 1
duration: 3000,
loop: true,
ease: 'inOut',
});
<div class="x-large spaced-evenly row">
<div class="col">
<div class="clock normal"></div>
<div class="label">normal</div>
</div>
<div class="col">
<div class="clock interpolated"></div>
<div class="label">interpolated [0,12]</div>
</div>
</div>