1

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)

2
  • possible duplicate of Activating Webkit CSS3 animation using Javascript Commented 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 around Commented Jan 7, 2012 at 22:44

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Or alternatively, you could add prefixfree to avoid having to declare different vendor-specific attributes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.