A+ 现代网页动画模块
Animate Plus 是一个专注于性能和创作灵活性的 JavaScript 动画库。它致力于提供稳定的 60 FPS,且体积不到 3 KB(经压缩和最小化),因此特别适合移动端使用。
npm install animateplus 或下载 animateplus.js,然后开始为元素添加动画:
import animate from "/animateplus.js";
animate({
elements: "div",
duration: 2000,
delay: index => index * 100,
transform: ["scale(0)", "scale(1)"]
})
.then(options => animate({
...options,
transform: ["translate(0%)", "translate(500%)"]
}));| 默认值 | 类型 |
|---|---|
null |
String | Element | NodeList | Array |
指定要添加动画的 DOM 元素。你可以传入 CSS 选择器或 DOM 元素。
animate({
elements: document.body.children,
transform: ["rotate(0turn)", "rotate(1turn)"]
});| 默认值 | 类型 |
|---|---|
out-elastic |
String |
决定动画的加速曲线。
| 常量 | 加速 | 减速 | 加速-减速 |
|---|---|---|---|
| linear | in-cubic | out-cubic | in-out-cubic |
| in-quartic | out-quartic | in-out-quartic | |
| in-quintic | out-quintic | in-out-quintic | |
| in-exponential | out-exponential | in-out-exponential | |
| in-circular | out-circular | in-out-circular | |
| in-elastic | out-elastic | in-out-elastic |
弹性缓动的振幅和周期可以通过提供以空格分隔的值来配置。
振幅默认为 1,周期默认为 0.4。
// Increase elasticity
animate({
elements: "span",
easing: "out-elastic 1.4 0.2",
transform: ["translate(0px)", "translate(500px)"]
});| 默认值 | 类型 |
|---|---|
1000 |
Number | Function |
决定动画的持续时间(以毫秒为单位)。通过传入一个回调函数,你可以为每个元素定义不同的持续时间。
暂无开放 Issues,或尚未同步最近议题。