添加animate.css类,然后使用remove移除元素

add animate.css classes then remove the element with remove

本文关键字:remove 元素 然后 animate css 添加      更新时间:2023-09-26

我正试图在我的标签/复选框中添加一些css类,然后删除这些类,然后在选中项目后删除它。尽管我很挣扎,只能做其中一个。

$(function () {
    $("label[for='<%= @todo.id %>']").click(function () {
        el = $("#todo-container-<%= @todo.id %>");
        el.addClass('animated fadeOut');
        el.one('webkitAnimationEnd oanimationend msAnimationEnd animationend',
        function (e) {
            el.removeClass('animated fadeOut');
            el.remove();
        });
    });
});

在这里,我尝试(在我的complete.js.erb文件中)在标签上单击(选中复选框),将animated和fadeOut类添加到容器中,然后在它褪色后删除该类和容器元素。

有人能帮我吗?我的代码只完成了我的2个需求中的1个

您可以查看"animationend"事件侦听器:

el.addEventListener("animationend", function().. , false);

更多信息可以在这里找到:

W3学校动画结束事件