Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

change rotation of object with JS and CSS in a loop

change rotation of object with JS and CSS in a loop

Problem

I'm trying to make an image change its rotation between 2 position in an infinite Loop. these are the 2 positions I have:

logo.style.webkitTransform = "rotate(3deg)"
logo.style.webkitTransform = "rotate(-3deg)"

Could someone help me with creating a delay and putting it into a loop. so far all my efforts didn't work. (I was trying using while for the loop + setTimeout)

or is there a better way to do it?

thanks in advance

Problem courtesy of: user1306732

Solution

Give this a try, see if it works

var dir = false;

setInterval(function(){
    (dir == false) ? logo.style.webkitTransform = "rotate(3deg)" : logo.style.webkitTransform = "rotate(-3deg)";
    dir = !dir;
}, 2000);
Solution courtesy of: slash197

Discussion

View additional discussion.



This post first appeared on CSS3 Recipes - The Solution To All Your Style Problems, please read the originial post: here

Share the post

change rotation of object with JS and CSS in a loop

×

Subscribe to Css3 Recipes - The Solution To All Your Style Problems

Get updates delivered right to your inbox!

Thank you for your subscription

×