1

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

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

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

4

1 回答 1

2

您可以将两者结合marginLeftheightd .animate(),例如:

$("#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(),因为如果你继续点击按钮,它看起来很奇怪)

于 2013-07-18T21:46:37.953 回答