Javascript jQuery:从上到下切换('慢')动画?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12102826/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery: toggle('slow') animation from top down?
提问by bevanb
In my code I use jQuery's toggle('slow')
animation to make a hidden div appear/disappear. It expands from the upper left to the bottom right.
在我的代码中,我使用 jQuery 的toggle('slow')
动画使隐藏的 div 出现/消失。它从左上角扩展到右下角。
How can I make it expand from the top towards the bottom, instead (no left-to-right growth)?
我怎样才能让它从顶部向底部扩展(没有从左到右的增长)?
回答by xdazz
回答by Eric
Try .slideDown('slow')
. Note that this will only work for sliding down (to reveal) and sliding up (to hide). For anything more complex, you're looking for .animate(...)
or something from jQuery UI.
试试.slideDown('slow')
。请注意,这仅适用于向下滑动(显示)和向上滑动(隐藏)。对于任何更复杂的东西,您正在寻找jQuery UI.animate(...)
或其他东西。
回答by Pablo Jomer
You could use jQuery's .animate
(http://api.jquery.com/animate/) instead. That way you can set the CSS properties before and after the expand and only alter the height.
您可以改用 jQuery .animate
( http://api.jquery.com/animate/)。这样你就可以在展开之前和之后设置 CSS 属性,并且只改变高度。
回答by Alexis Morozo
Try to put an with onclick $('#DIV-ID').toggle('slow'); return false;
尝试使用 onclick $('#DIV-ID').toggle('slow'); 返回假;
Just like this: <a onclick="$('#DIV-ID').toggle('slow'); return false;">DROP DOWN</a>
像这样: <a onclick="$('#DIV-ID').toggle('slow'); return false;">DROP DOWN</a>