I'm making a drop down navigation and I would like to use an arrow that rotates to toggle it.
I have this https://jsfiddle.net/jaUJm/39/
$(document).ready(function() {
$( ".toggle" ).click( function() {
$("#image").css({'transform': 'rotate(-180deg)'});
});
});
I'm just not sure how to make it reset, as in, complete the rotation so it's pointing down again when it's clicked the second and subsequent times.
Maybe a .flip class with
.flip { transform: rotate(-180deg);}
and use an if()
and addClass()/removeCLass()
?
Thank you!
You can use toggleClass
$(document).ready(function() {
$( ".toggle" ).click( function() {
$("#image").toggleClass('flip');
});
});
#image {
-moz-transition: transform 1s;
-webkit-transition: transform 1s;
transition: transform 1s;
}
.flip {
transform: rotate(-180deg);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<img class="toggle" id="image" src="https://i.imgur.com/uLlPUfM.png"/>
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