2013-07-18 37 views
1

我怎样才能使动画及以下滑下功能在完全相同的时间和持续时间发生:jQuery的动画,并同时了slideDown

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

我上面的代码下滑之前制作动画。如果我移动动画下方的功能,它是滑动下来,然后动画

回答

2

你可以同时结合了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"); 
}); 

DEMO:http://jsfiddle.net/sDrtE/

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

+0

谢谢你ve很多。这工作正常。我需要向上滑动并将margin-left设置为0。动画函数中的slideUp等价于什么? – Jamol

+0

@jCloud现在,我已经给了你基本的结构 - 只是扭转'marginLeft'的值:http://jsfiddle.net/sDrtE/2/ – Ian

+0

是的,我不知道那个切换也可以隐藏。但我用高度:“隐藏”,而不是切换到滑块 – Jamol