I have been working in an accordion, but for some odd reason the following code:
<style>
.collapse {
position: relative;
height: 0;
overflow: hidden;
-webkit-transition: height .35s ease;
-moz-transition: height .35s ease;
-o-transition: height .35s ease;
transition: height .35s ease;
}
.collapse.in {
height: auto;
}
</style>
<div class="accordion">
<div class="something">
<a class="" >Accordion Pane 1</a>
</div>
<div class="accordion-body collapse">
<div class="accordion-inner"> content </div>
</div>
</div>
<script>
$('.something').click(function(event){
event.preventDefault();
$(this).next('.accordion-body').toggleClass('in');
})
</script>
http://jsfiddle.net/CvdXK/
doesn't seem to work. The height doesn't animate. And i dont know why.
Thanks very much in advance.
We can't transition height , but we can transition max-height , since it has an explicit value. At any given moment, the actual height of the element will be the minimum of the height and the max-height .
For animate the "height" of element with CSS Transitions you need use "max-height". If use the "height: auto", the effect not works. Is necessary some value for the CSS create a CSS animate, and you can use "max-height" with a great value for emulate this effect.
To trigger an element's transition, toggle a class name on that element that triggers it. To pause an element's transition, use getComputedStyle and getPropertyValue at the point in the transition you want to pause it. Then set those CSS properties of that element equal to those values you just got.
CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.
I think you need to set a specific height instead of auto
for the transition to happen on height.
.collapse {
height: 0;
position: relative;
overflow: hidden;
-webkit-transition: height 1.35s ease;
-moz-transition: height 1.35s ease;
-o-transition: height 1.35s ease;
transition: height 1.35s ease;
background-color: #cecece;
}
.collapse.in {
height: 200px; /*Set the height here*/
}
Demo
Or another option transition on max-height, like a max-height that is near impossible.
.collapse {
max-height:0px;
position: relative;
overflow: hidden;
-webkit-transition: max-height 0.35s ease-in-out;
-moz-transition: max-height 0.35s ease-in-out;
-o-transition: max-height 0.35s ease-in-out;
transition: max-height 0.35s ease-in-out;
background-color: #cecece;
}
.collapse.in {
max-height:1000px;
}
Demo2
Here is a quote from this page:
Transitioning gradients: Not every CSS property can be transitioned, and the basic rule is that you can only transition through absolute values. For example, you can’t transition between a height of 0px to auto. The browser can’t calculate the intermediate transition values, so the property change is instant.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With