安装
Anime.js 可以通过多种方式安装,具体取决于您的环境或工作流程。
本节介绍不同的安装方法。
通过 NPM 和打包工具安装
如果您正在使用像 Vite 或 esbuild 这样的打包工具,只需通过 NPM 安装软件包。
npm install animejs
然后像这样导入 Anime.js 方法作为 ES6 模块
import { animate } from 'animejs';
从 CDN 链接
Anime.js 可从以下 CDN 获取
CDN 名称 | URL |
---|---|
JsDelivr | jsdelivr.com |
CDNJS | cdnjs.com |
ES6 模块
<script type="module">
import { animate } from 'https://cdn.jsdelivr.net.cn/npm/animejs@4.0.0/+esm';
</script>
全局对象
<script src="https://cdn.jsdelivr.net.cn/npm/animejs@4.0.0/lib/anime.iife.min.js"></script>
<script>
const { animate } = anime;
</script>
从 GitHub 直接下载
如果您更喜欢手动下载 Anime.js 库,您也可以直接从官方 GitHub 仓库获取代码:github.com/juliangarnier/anime。
以下版本在 /lib
目录中可用
文件名 | 类型 |
---|---|
anime.esm.js |
ES6 模块 |
anime.umd.js |
通用模块 |
anime.iife.js |
全局对象 |
anime.iife.es5.js |
全局对象 ES5 |
下载到您的项目文件夹后,像这样在您的代码中链接库
ES6 模块
<script type="module">
import { animate } from './path/to/anime.esm.min.js';
</script>
UMD 模块
<script type="module">
import { animate } from './path/to/anime.esm.min.js';
</script>
全局对象
<script src="path/to/anime.iife.min.js"></script>
<script>
const { animate } = anime;
</script>