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. 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. 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.
you can try 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.