gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 07:00:11 25 4
gpt4 key购买 nike

我的页面上有克隆和删除功能,我想分别对其应用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com