Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery height animate() doesn't work

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

the JS:

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

I need to slide the 'ul' tag Up/Down without 'really' disappearing it. What's wrong with the code? doesn't make it yet. thanks.

like image 902
egig Avatar asked Dec 01 '22 04:12

egig


2 Answers

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

if ($('ul').height() == 0) {
}
like image 81
udidu Avatar answered Dec 04 '22 10:12

udidu


You can achieve this just using slideToggle.

Try this:

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

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

like image 43
mattytommo Avatar answered Dec 04 '22 11:12

mattytommo