【问题标题】:jQuery animate and slideDown simultaneouslyjQuery动画和slideDown同时
【发布时间】:2013-07-18 01:05:37
【问题描述】:

如何使下面的动画和向下滑动功能在完全相同的时间和持续时间内发生:

current_item.css('margin-left', 0);
current_item.animate({ 'marginLeft': '20px'});
current_item.slideDown(300, 'swing');

我上面的代码是在向下滑动之前对其进行动画处理。如果我将动画功能移到下面,它会向下滑动然后动画

【问题讨论】:

    标签: jquery jquery-animate slide simultaneous sametime


    【解决方案1】:

    您可以将marginLeftheight 组合成.animate()d,例如:

    $("#btn1").one("click", function () {
        var current_item = $("#div1");
        current_item.css('margin-left', 0);
        current_item.animate({
            marginLeft: "20px",
            height: "toggle"
        }, 300, "swing");
    });
    

    演示: http://jsfiddle.net/sDrtE/

    (是的,我的意思是使用.one() 而不是.on(),因为如果你一直点击按钮看起来很奇怪)

    【讨论】:

    • 非常感谢。这很好用。我还需要向上滑动并将 margin-left 设置为 0。动画函数中的 slideUp 等价物是什么?
    • @jCloud 来吧,我已经给你基本的结构了——只要把marginLeft的值倒过来:jsfiddle.net/sDrtE/2
    • 是的,我不知道切换也适用于隐藏。但我使用 height: "hide" 而不是 toggle 来滑动块
    • @jCloud 啊,我明白了。那么这里有一个更完整的“切换”方式(如果你在乎的话):jsfiddle.net/cfTXd
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 2012-07-06
    • 1970-01-01
    • 2013-10-27
    相关资源
    最近更新 更多