0

how to make a button with javascript when the user presses it to rotate an object 180 moires? (for my site)

<input type="button" value="button">

I have no idea how to do it.

1

3 Answers 3

4

Simply css3 rotate and onclick event: https://jsfiddle.net/xxarLyc6/

One class and default rotate:

div{
  -ms-transform: rotate(0deg); /* IE 9 */
  -webkit-transform: rotate(0deg); /* Chrome, Safari, Opera */
  transform: rotate(0deg);
}
.rotated{
  -ms-transform: rotate(180deg); /* IE 9 */
  -webkit-transform: rotate(180deg); /* Chrome, Safari, Opera */
  transform: rotate(180deg);
}

Javascript onclick event for button:

var button=document.getElementById("button");
button.onclick=function(){
  document.getElementById("torotate").className = "rotated";
}
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the CSS3 rotate property how this:

HTML:

<input type="button" value="button" id="button">

CSS:

.rotate-180 { -moz-transform: rotate(180deg); -webkit-transform: rotate(180deg); -o-transform: rotate(180deg); -ms-transform: rotate(180deg); }

JS:

$("#button").click(function(){
   $(this).toggleClass("rotate-180");
})

DEMO: http://jsfiddle.net/1x84r9p6/

Comments

0

I would suggest using the Web Animations API (chrome, firefox, and opera all partially support it):

Simplest Reference on how to use.

For your code this would do:

element.animate([{transform: "rotate(0deg)"}, {transform: "rotate(100deg)"}], {duration: 2000});

Comments

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.