[英]jQuery animate height not toggle expand every time
I am having trouble getting jQuery animate to work .To start the div is hidden with .hide(), then onclick of a button I want to expand the height of the div. 我无法让jQuery动画工作。要启动div,用.hide()隐藏,然后单击按钮,我想扩展div的高度。 Toggle animate works perfect, but I don't want toggle. 切换动画完美,但我不想切换。
Toggle does this: The div is hidden, I fire the code below, works perfect, then the div gets hidden, fire it again- the div pops up full height and the animates down to 0px. Toggle这样做:div是隐藏的,我触发下面的代码,工作完美,然后div被隐藏,再次触发它 - div弹出全高,动画下降到0px。 I want it to go from hidden to expanding every time. 我希望它每次都从隐藏到扩展。
$('#logincontainer').animate(
{ 'height': 'toggle' }, 'slow'
);
I tried 我试过了
{ 'height': '552px' }, 'slow'
{ 'height': 'auto' }, 'slow'
var h = document.getElementById('logincontainer').scrollHeight;
{ 'height': h + 'px' }, 'slow'
I just want to expand the height to 552px, which the div already is every time. 我只想将高度扩展到552px,每次都是div。
you can try slideToggle()
: 你可以试试slideToggle()
:
Display or hide the matched elements with a sliding motion. 通过滑动显示或隐藏匹配的元素。
$('#trigger').click(function(e){
e.preventDefault()
$('#logincontainer').slideToggle('slow');
})
$('#logincontainer').animate(
{ 'height': 'show' }, 'slow'
);
'show' was the magic jQuery word I was looking for to expand everytime, I will have to manually set the height back to 0 when hidden as well. 'show'是我每次都想要扩展的魔术jQuery单词,我必须在隐藏时手动将高度设置回0。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.