css-animations - 将 Clippath CSS 关键帧动画转置为animejs 动画
问题描述
我有这个运行良好的关键帧动画:
body{
background: red;
}
.myAnimation{
width: 100px;
height: 200px;
background: blue;
clip-path: inset(100px 50px);
animation: myClipAnim 3s infinite;
transition: animation 2s;
}
@keyframes myClipAnim {
100% { clip-path: inset(0) }
}
<body>
<div class="myAnimation"></div>
</body>
现在我想用animejs重现完全相同的动画,所以我尝试了以下方法:
anime({
targets: '.myAnimation',
direction: 'reverse',
keyframes: [
{clipPath: 'inset(0)' }
],
duration: 3000
});
body{
background: red;
}
.myAnimation{
width: 100px;
height: 200px;
background: blue;
clip-path: inset(100px 50px);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js"></script>
<body>
<div class="myAnimation"></div>
</body>
但它不起作用,我不明白为什么。我哪里错了?请帮忙!
解决方案
在animejs 中,您必须指定至少两个关键帧(开始帧和结束帧),否则它将是静态的。
因此,在添加第二个 keyFrame 之后{clipPath: 'inset(100px 50px)'}
,我添加了 loop 和 easing 属性以匹配基于 CSS 的示例。
anime({
targets: '.myAnimation',
direction: 'reverse',
easing: 'easeInOutSine', // choose from https://animejs.com/documentation/#pennerFunctions
loop: true, // let the animation repeat itself
keyframes: [
{clipPath: 'inset(0)' }, // start frame
{clipPath: 'inset(100px 50px)'}, // end frame
],
duration: 3000
});
body{
background: red;
}
.myAnimation{
width: 100px;
height: 200px;
background: blue;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.0/anime.min.js"></script>
<body>
<div class="myAnimation"></div>
</body>
推荐阅读
- java - Drawerlayout 拦截所有点击
- rest - Dotnet核心:从Web api发送字节数组作为文件而不将其保存到磁盘
- javascript - iframe-resizer 中的错误处理?
- php - 在 Woocommerce 3 中更改订单创建时的默认结帐字段值
- javascript - 在生产代码中使用断言?(Node.js 中的 TDD)
- c# - UAC 提示时设置编辑器
- android - com.android.builder.dexing.DexArchiveBuilderException:处理失败。
- android - 我收到一个错误:找不到 com.google.android.gms.internal.zzbgl 的类文件
- makefile - Makefile.inc 不存在 plexe-veins
- javascript - BrowserSync 与 Gulp 在更改完成之前重新加载浏览器