When I click on a button, I want a div to rotate, just as I would do with a CSS3 transition: rotate(350deg);. How would I do this with either CSS or JS? (If it can be done with CSS I'd perfer that instead)
-
possible duplicate of Activating Webkit CSS3 animation using Javascriptrobertc– robertc2012-01-07 22:43:59 +00:00Commented Jan 7, 2012 at 22:43
-
you can't animate with css2 as there's no transition; you will have to use jQuery and a plugin for it, google aroundmreq– mreq2012-01-07 22:44:33 +00:00Commented Jan 7, 2012 at 22:44
Add a comment
|
1 Answer
In the onclick event of the button, put:
document.getElementById("yourDivId").className += " rotate";
In the CSS:
#yourDivId {
transition: transform 1s;
}
.rotate {
transform: rotate(360deg);
}
You'd have to add the browser specfic prefixes (-moz-, -webkit-) to the transition and transform, but this should work for you.
1 Comment
Klemen Slavič
Or alternatively, you could add prefixfree to avoid having to declare different vendor-specific attributes.