首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对Clone和Remove函数应用动画

对Clone和Remove函数应用动画
EN

Stack Overflow用户
提问于 2011-01-12 06:28:55
回答 1查看 2.5K关注 0票数 1

我在我的页面上有克隆和删除函数,我想对它们分别应用slideDown / slideUp动画:

代码语言:javascript
复制
$('#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;
});

我试过这样做,但要么不起作用,要么动画非常抖动。有人知道这是怎么做的吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-01-12 06:33:30

用于克隆

代码语言:javascript
复制
$('#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;
});

而对于删除

代码语言:javascript
复制
$('.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/上演示

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4663399

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档