我的页面上有克隆和删除功能,我想分别对其应用 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;
});
关于jquery - 在克隆和删除功能上应用动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4663399/