我在我的页面上有克隆和删除函数,我想对它们分别应用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;
});我试过这样做,但要么不起作用,要么动画非常抖动。有人知道这是怎么做的吗?
发布于 2011-01-12 06:33:30
用于克隆
$('#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/上演示
https://stackoverflow.com/questions/4663399
复制相似问题