javascript - 为什么宽度:0 不动画(anime.js)
问题描述
我正在尝试创建一个元素宽度的动画,但即使是这个基本代码也不起作用,我不知道为什么,也许有人可以。
<script src="anime.min.js"></script>
<script src="jquery-3.1.0.js"></script>
<div id="centered">
</div>
<style>
#centered {
width: 500px;
height: 40vh;
background-color: blueviolet;
}
</style>
<script>
let t = anime.timeline({
target: '#centered',
loop: false,
autoplay: false,
width: 0,
duration: 1000,
});
t.play();
</script>
解决方案
以下解决方案如何?
示例 1(带时间线)
var t = anime.timeline({
duration: 1000,
loop: false,
autoplay: false,
});
t.add({
targets: '#centered',
width: 0
})
t.play();
示例 2(无时间线)
var t = anime({
duration: 1000,
loop: false,
autoplay: false,
targets: '#centered',
width: 0
});
t.play();
有关更多信息,最好查看官方文档。 https://animejs.com/documentation/
推荐阅读
- tableau-api - Tableau 为三个字段创建通用自定义素材箱
- javascript - 尝试从不同的函数中使用 Async 和 Await
- r - 使用 R 中更改的数据和变量名称运行相同的代码
- c++ - 如何测试文件是否被锁定和/或只读而不打开?
- python - 使用 Python 的密码保护 zip 文件
- amazon-web-services - Amazon Cognito - 有没有办法绕过注册前 Lambda 触发器
- python - 避免在 matplotlib 中的 X 轴上排序,并用多个 y 轴绘制公共 X 轴
- sql - 如何以直接、简单的方式获取 MS SQL Server 和数据库空间信息
- python - 同时运行多个使用用户输入和while循环的python脚本
- php - $request 根据我转储它的位置返回不同的值