Liam Liam - 1 year ago 365
Javascript Question

ToggleClass animate jQuery?

I have a section on my website that when a user clicks id like it to expand, Im using the jQuery toggleClass for this...

expandable: function(e) {
e.preventDefault();
$(this).closest('article').toggleClass('expanded', 1000);
}


This is working fine, only Id like to somehow animate it? In chrome my article slowly grows to the new size, only in firefox it 'instantly' resizes itself with no animation, is there a way to have this animate?

Answer Source

jQuery UI extends the jQuery native toggleClass to take a second optional parameter: duration

toggleClass( class, [duration] )

Docs + DEMO