I want an image to rotate 180 degrees when hovered over. When the image is clicked, I want it to stay in that position until clicked again to return to its original position.
While I've tried using a combination of CSS for the hover effect, it doesn't persist. I came across some jQuery examples but found them too basic to understand how to make the image return to its original position when clicked again.
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);
}
Any help would be appreciated.
EDIT: Here's the 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: Is it possible for the image to rotate back to its original position on hover without needing to click it again? For example:
In Position A, hover, rotate, click, stay in Position B. In Position B, hover, rotate back, click, stay in Position A again.