I'd like to have an image rotate 180 degrees on hover. When the image is clicked/selected I'd like the image to remain in that position until it is selected again when it should return to its original position.
I've tried a combination of CSS which works fine for the hover but won't persist. I then found a few posts using jQuery but don't understand it enough to make the image return when selected again as the example I found was very basic.
The HTML
<div class="conversionFormE" id="switch1">
<label class="swapHide">Swap?</label>
<input type="button" class="rotate" id="switch" name="switch" value="" onclick="switchUnits()"/>
</div>
Some of the CSS
.rotate {
-webkit-transition-duration: 0.8s;
-moz-transition-duration: 0.8s;
-o-transition-duration: 0.8s;
transition-duration: 0.8s;
-webkit-transition-property: -webkit-transform;
-moz-transition-property: -moz-transform;
-o-transition-property: -o-transform;
transition-property: transform;
overflow:hidden;
}
.rotate:hover {
-webkit-transform:rotate(180deg);
-moz-transform:rotate(180deg);
-o-transform:rotate(180deg);
}
Thanks for any help.
EDIT: onClick function as requested.
function switchUnits(){
//need to get values before swap to and from around.
var from = $("#from").val();
var to = $("#to").val();
//switches the details
$("#to #"+from).attr("selected","selected");
$("#from #"+to).attr("selected","selected");
//gets values after switch
from = $("#from").val();
to = $("#to").val();
//run convert
convertUnits();
}
EDIT: Would very much like for this to be achieved: Possible for image to rotate on hover again back to it's original position without the need for clicking it? so it would be:
in posA, hover, rotate, click, stay in posB. in posB, hover, rotate back, click, stay in posA again.