JQuery () animation height not working

I just created this: jsfiddle.net/MWzDe/ ,

JS:

$('button').click(function () { if ($('ul').height = 0) { $('ul').animate({'height':'100%'},'slow'); } else { $('ul').animate({'height': 0},'slow'); }}); 

I need to move the tag 'ul' up / down without 'really' to disappear. What is wrong with the code? doesn't do it yet. thanks.

+4
source share
7 answers

.height is a function: use $('ul').height() to get a height like this

 if ($('ul').height() == 0) { } 
+6
source

You can achieve this using slideToggle .

Try the following:

 $('button').click(function () { $("ul").slideToggle("slow"); }); 

Fiddle: http://jsfiddle.net/MWzDe/3/

+4
source

Try:

 $('button').click(function () { $('ul').animate({ 'height':'toggle' }, 'slow'); }); 

Feed here

+4
source

since you are using jquery, why not use .slideToggle() ?

 $('button').click(function() { $('ul').slideToggle('slow'); }); 
+2
source

Use slideToggle ()

DEMO VIEW

 $('button').click(function () { $('ul').slideToggle('slow'); }); 
+2
source

Just use the .slideToggle function. DEMO HERE

 $('button').click(function () { $('ul').slideToggle(); }); 
+2
source

the following code uses animation

 $('button').on(click, function() { $('ul').animate({height: 'toggle'},'slow'); }) 
0
source

All Articles