I have an image I want to be rotated,
<img src="images/anchor.png" alt="robot image" class="robot rotate" width="100px" height="100px" />
The following css code to rotate the image
.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(-90deg);
-moz-transform:rotate(-90deg);
-o-transform:rotate(-90deg);
}
And lastly the jquery to make it happen onclick
$(document).ready(function () {
$('img.rotate').click(function () {
$('img.rotate').addClass('hover');
}, function () {
$('img.rotate').removeClass('hover');
});
alert("working?");
});
But when I click on the image all that happens is my image rotates due to my css. What I want to happen is when the image is clicked then it will begin to rotate, not when I hover over it.
Here's my fiddle http://jsfiddle.net/sneakmiggz/7B8Ya/
.hover(). if you don't want it to do that on hover, i recommend avoiding that method..hoverclass..click()expects one callback function, not two. Also, inside the callback you can make use of$(this)rather than retraversing the DOM for the node again...