1

I have used javascript code to increase and decrease the height of div on click event. But i also want to apply transition-duration property so that transition goes smoothly.

Here is the css code

#content {
    height: auto;
    width:400px;
    background-color:#F30;
    transition-duration:2s;
}

#content.expand {
    height: 300px;
    transition-duration:2s;
}

This is the javascript code

function chk()
{
    var node = document.getElementById('content');

    node.classList.toggle('expand');
}

The function is working properly. I have applied transition property, but that is not working.

3
  • Works fine here: jsfiddle.net/oGeez/Lw76f - What's the problem? Commented Dec 3, 2013 at 9:33
  • if you are trying on safari you need to wirte -webkit-transition-duration :2s; Commented Dec 3, 2013 at 9:33
  • @Terror.Blade Transition is not working in mozilla. Works fine in chrome and safari. Commented Dec 3, 2013 at 9:42

3 Answers 3

2

According to Bugzilla, this is the Bug 571344.

Transition to and from auto affects Firefox (that doesn't transition at all), but works in quirks ways in other browsers too.

For example, in Chrome height: auto is treated like height: 0 in the transition, and you will see the red background of the example being smaller up to disappear, then restoring to the real "auto" value.

Simply specify an height, and it will work good, in every browser: Running demo

Sign up to request clarification or add additional context in comments.

Comments

0

Try cross browser solution like this:

 transition-duration:2s; 
 -o-transition-duration:2s; 
 -moz-transition-duration:2s; 
 -webkit-transition-duration:2s;

instead of only transition-duration:2s;

1 Comment

Its still not working in mozilla. It increases and decreases in a sudden. No effect of transition property.
0

It is a problem with the value transform, in Mozilla it is prefixed with -moz-transform.

#content {
    height: auto;
    width:400px;
    background-color:#F30;
    -webkit-transition:all .1s ease;
 -moz-transition:all .1s ease;
 -ms-transition:all .1s ease;
 transition:all .1s ease;
}

#content.expand {
    height: 300px;
   -webkit-transition:all .1s ease;
 -moz-transition:all .1s ease;
 -ms-transition:all .1s ease;
 transition:all .1s ease; 
}

3 Comments

where should i put the time duration? can you please show me?
checked it. still not working. Its working in chrome, but not in mozilla.
Your efforts are great @Terror.Blade, but that is not working. Can you please check this in your mozilla browser. It may be due to some problem in browser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.