Looking for a bit of help here using FA5 (SVG w/ JS) and Jquery to animate an icon so it will rotate 180 on the click of an element.
My HTML looks like this:
<div class="card-block">
<a id="student-change" data-toggle="collapse" href="#classBreakdownPanel" role="button" aria-expanded="false" aria-controls="classBreakdownPanel">
<div class="row">
<div class="col">
<span class="card-text text-primary">View details</p>
</div>
<div class="col">
<i id="blueCaret" class="fas fa-2x blue-caret fa-caret-circle-up float-right"></i>
</div>
</div>
</a>
</div>
When rendered in browser it becomes this:
<div class="card-block">
<a id="student-change" data-toggle="collapse" href="#classBreakdownPanel" role="button" aria-expanded="false" aria-controls="classBreakdownPanel" class="collapsed">
<div class="row">
<div class="col">
<span class="card-text text-primary">View details<p></p>
</span></div>
<div class="col">
<svg id="blueCaret" class="svg-inline--fa fa-caret-circle-up fa-w-16 fa-2x blue-caret float-right" aria-hidden="true" data-prefix="fas" data-icon="caret-circle-up" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M8 256C8 119 119 8 256 8s248 111 248 248-111 248-248 248S8 393 8 256zm379.5 27.5l-123-123c-4.7-4.7-12.3-4.7-17 0l-123 123c-7.6 7.6-2.2 20.5 8.5 20.5h246c10.7 0 16.1-12.9 8.5-20.5z"></path></svg><!-- <i id="blueCaret" class="fas fa-2x blue-caret fa-caret-circle-up float-right"></i> -->
</div>
</div>
</a>
</div>
CSS looks like this:
#blueCaret{
transition-duration: 0.8s;
transition-property: transform;
}
.rotated{
-moz-transform:rotate(180deg);
-webkit-transform:rotate(180deg);
transform:rotate(180deg);
}
and some very simple jquery:
$('#student-change').click(function(){
$('#blueCaret').toggleClass("rotated");
console.log('it should turn');
});
This works in that the icon goes from pointing up on load, to down when the div below it is expanded on click, and then points up again when the user clicks it again.
I would like it to nicely rotate to position however.
Right now it literally just switches from up to down instantly - but I'd like to animate the transition so it looks nice and fluid by rotating it.
I'm sure I am missing something simple, but I can't seem to find how to do this.