jquery - 在克隆和删除功能上应用动画

标签 jquery jquery-animate

我的页面上有克隆和删除功能,我想分别对其应用 SlideDown/SlideUp 动画:

$('#add-item').click(function(){
    var divCloned = $('.form-fields:first').clone();
    divCloned.insertAfter('.form-fields:last');
    return false;
});

$('.remove').live('click', function(){
    if(confirm("Are you sure you wish to remove this item?"))
    {
        $(this).parent().remove();
    }
    return false;
});

我尝试过这样做,但要么不起作用,要么动画非常不稳定。有人知道如何做到这一点吗?

最佳答案

用于克隆

$('#add-item').click(function(){
    var divCloned = $('.form-fields:first').clone();
    // first we hide it (set display to none), then we add it in the DOM 
    // and lastly we aninmate it with slideDown
    divCloned.hide().insertAfter('.form-fields:last').slideDown('fast');
    return false;
});

以及删除

$('.remove').live('click', function(){
    if(confirm("Are you sure you wish to remove this item?"))
    {
        // we use the callback method of the slideUp function
        // so that the removal happens after the animation..
        $(this).parent().slideUp('fast',function(){ $(this).remove(); });
    }
    return false;
});

演示地址:http://www.jsfiddle.net/gaby/qf4j3/

关于jquery - 在克隆和删除功能上应用动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4663399/

相关文章:

javascript - 匹配文本等于传递值 Jquery

javascript - 将所有元素的点击绑定(bind)替换为单个文档(('click')?

jquery - 从 microsoft Ajax.BeginForm 迁移到 jquery

javascript - 打开 "Save As"对话框下载图片

javascript - 像 Pinterest 一样接管浏览器滚动条的模态窗口

css - 不能动画兄弟元素

javascript - Animate.css 滚动错误 chrome/firefox

javascript - jquery - 如何排队一系列的 css 属性更改

jquery - 如何启动/停止/重新启动 jQuery 动画

javascript - 尝试实现正文标签颜色更改