缓动
一组缓动函数和基于物理的弹簧生成器
使用 缓动函数编辑器 来可视化、创建和自定义缓动函数。
所有缓动函数都可以通过从主 'animejs' 模块导入的 easings 对象获取:
import { easings } from 'animejs';
easings.eases.inOut(3);
easings.cubicBezier(.7, .1, .5, .9);
easings.spring({ bounce: .35 });
或者直接从主 'animejs' 模块导入:
import { eases, cubicBezier, spring } from 'animejs';
eases.inOut(3);
cubicBezier(.7, .1, .5, .9);
spring({ bounce: .35 });
或者作为独立模块从 'animejs/easings' 子路径 导入:
import { eases, cubicBezier, spring } from 'animejs/easings';
缓动函数和弹簧函数可以传递给 ease 和 playbackEase 参数,用于 animate() 方法,或用于 ease 参数,应用于 stagger() 函数。
import { cubicBezier, linear, spring } from 'animejs';
animate(target, { x: 100, ease: 'inOut(3)' });
animate(target, { x: 100, ease: cubicBezier(.7, .1, .5, .9) });
animate(target, { x: 100, ease: spring({ bounce: .35 }) }); 缓动代码示例
import { animate, waapi, cubicBezier, spring } from 'animejs';
animate('.row:nth-child(1) .square', {
x: '17rem',
rotate: 360,
ease: 'out(3)', // Built-in ease
});
animate('.row:nth-child(2) .square', {
x: '17rem',
rotate: 360,
ease: cubicBezier(.7, .1, .5, .9), // Custom cubic Bezier curves
});
waapi.animate('.row:nth-child(3) .square', {
x: '17rem',
rotate: 360,
ease: spring({ bounce: .35 }), // Spring physics
});
<div class="medium row">
<div class="square"></div>
<div class="padded label">'inQuad'</div>
</div>
<div class="medium row">
<div class="square"></div>
<div class="padded label">cubicBezier(.7, .1, .5, .9)</div>
</div>
<div class="medium row">
<div class="square"></div>
<div class="padded label">spring({ bounce: 1.25 })</div>
</div>
在本节