I have a working solution for a panel wrapped in an bootstrap 3 accordion.
How can I animate change of the chevron state from ">" to "^" with a 90 degrees rotation?
.panel-heading .accordion-toggle:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: grey;
}
.panel-heading .accordion-toggle.collapsed:after {
content: "\e080";
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#importationCollapse">Importation</a>
</h3>
</div>
<div id="importationCollapse" class="panel-collapse collapse in">
<div class="panel-body">
<p>Content: blahblah</p>
</div>
</div>
</div>
</div>
[EDIT] I am looking for a smooth rotation, I already how to change the chevron state.
You can simply replace
.panel-heading .accordion-toggle.collapsed:after {
content: "\e080";
}
With the following
.panel-heading .accordion-toggle.collapsed:after {
transform: rotateX(180deg);
}
That should do the trick, instead of using another character. Demo on Codepen
To animate the rotation you can add the following
.panel-heading .accordion-toggle:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: grey;
transition: transform 0.5s;
transform-origin: 8px 7px;
}
And to rotate along Z axis
.panel-heading .accordion-toggle.collapsed:after {
transform: rotateZ(180deg);
}
You can experiment with transform-origin to get your desired result.
Demo on Codepen
Instead of changing content you can try with transition and transform: rotate() to get it done. check below snippet for reference.
.panel-heading .accordion-toggle:after {
font-family: 'Glyphicons Halflings';
content: "\e114";
float: right;
color: grey;
transition: all 0.5s ease;
}
.panel-heading .accordion-toggle.collapsed:after {
/*content: "\e080";*/
transform: rotate(180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<div class="panel-group" id="accordion">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion" href="#importationCollapse">Importation</a>
</h3>
</div>
<div id="importationCollapse" class="panel-collapse collapse in">
<div class="panel-body">
<p>Content: blahblah</p>
</div>
</div>
</div>
</div>
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