如何在删除其中一个列表时使动画更平滑
How to make the animation smoother when one of the list is removed
我有一个元素列表。单击每个元素时,它们会从列表中删除,并带有一些动画。这种情况是,当一个元素从列表中删除时,其余元素会在没有任何动画的情况下向上移动。所以我可以让它更流畅,而不仅仅是跳跃。这是我的代码块
风格
li{
list-style-type: none;
padding: 10px;
cursor: pointer;
}
li.removed-item {
animation: removed-item-animation 1s cubic-bezier(0.55, -0.04, 0.91, 0.94) forwards;
/*transform origin is moved to the bottom left corner*/
transform-origin: 0% 100%;
}
@keyframes removed-item-animation {
0% {
opacity: 1;
transform: rotateZ(0);
}
100% {
opacity: 0;
transform: translateY(600px) rotateZ(90deg);
}
}
Jquery
$('li').click(function () {
$(this).addClass('removed-item').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function(e) {
$(this).remove();
});
e.stopImmediatePropagation();
});
工作小提琴
你可以先使用 .slideUp(),完成后再使用 .remove()。
$('li').click(function () {
$(this).addClass('removed-item').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) {
$(this).slideUp(function(){
$(this).remove();
});
});
});
如有必要,您还可以控制 slideUp 动画持续时间
.slideUp( [持续时间] [, 完成 ] )
$('li').click(function () {
$(this).addClass('removed-item').one('webkitAnimationEnd oanimationend msAnimationEnd animationend', function (e) {
$(this).slideUp(function(){
$(this).remove();
});
});
});
li {
list-style-type: none;
padding: 10px;
cursor: pointer;
}
li.removed-item {
animation: removed-item-animation 1s cubic-bezier(0.55, -0.04, 0.91, 0.94) forwards;
/*transform origin is moved to the bottom left corner*/
transform-origin: 0% 100%;
}
@keyframes removed-item-animation {
0% {
opacity: 1;
transform: rotateZ(0);
}
100% {
opacity: 0;
transform: translateY(600px) rotateZ(90deg);
}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<ul>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
<li>List 1</li>
</ul>
如果您将高度添加到删除项目动画中,例如 0% 时为 50px,100% 时为 0px,则当列表被删除时,列表将动画化。
@keyframes removed-item-animation {
0% {
padding: 0px 10px;
height: 50px;
opacity: 1;
transform: rotateZ(0);
}
100% {
padding: 0px 10px;
height: 0px;
opacity: 0;
transform: translateY(600px) rotateZ(90deg);
}
}
相关文章:
- 从javascript创建一个列表
- 将jsp文件下拉列表中的选定项分配给一个java变量(比如String selection)
- 从HTTPGET返回一个自定义对象列表,以便在Angular 2应用程序中使用
- 当在Ember中点击一个项目时,我如何将一个活动类添加到项目列表中
- 如何在用户返回和上一个按钮时刷新下拉列表
- jQuery-将列表项的一个元素移动到同一项的另一个元素中+对我的列表中的每个项执行此操作
- 如何为下拉列表的每个选项添加一个属性
- 在下拉列表中选择一个选项的值
- 在Twitter BootStrap嵌套下拉列表中托管一个选择列表(IE 9特定)
- 使用jquery从列表项中移除类,并将一个类添加到另一个列表项中
- 我在下拉列表中尝试了下一个和前五年的html代码.接下来的5年我都过得很好.我怎样才能拿到之前的5年
- 我想在我的准备列表项上创建一个按钮
- 如何使用jquery将所选项目从一个下拉组列表(optgroup)移动到另一个下拉列表(optgroup)
- 我创建了一个Javascript待办事项列表,但想知道如何在浏览器刷新后保留这些帖子
- 如何将一个类一个接一个地添加到列表中的每个元素中
- JSON编码一个HTML列表——所有子项都显示在所有父项上
- 什么'是从对象列表中一次编辑一个对象的正确Angular/Firebase方法
- 我需要使用什么语法来向一个对象的成员添加一个临时数组,该成员等同于一个字符串的通用列表
- 如何强制用户从下拉列表和按钮中选择一个值以启用保存按钮
- 在另一个下拉列表中的选择上切换下拉列表中选项的可见性