How to rotate a DIV through CSS or Javascript

S

Sura

Hi

Is it possible to rotate a DIV to any particular angle (e.g. 21
degrees) by CSS or Javascript? I have seen samples on the net which
rotates it to 90, 180 and 270, yet I am looking at flexibility with
the angle. Also The content inside the DIV should not get distorted as
it happens with some example which I have seen where an image is being
rotated.

Please let me know if you are aware of a solution.

Thanks
 
M

Martin Honnen

Sura said:
Is it possible to rotate a DIV to any particular angle (e.g. 21
degrees) by CSS or Javascript? I have seen samples on the net which
rotates it to 90, 180 and 270, yet I am looking at flexibility with
the angle. Also The content inside the DIV should not get distorted as
it happens with some example which I have seen where an image is being
rotated.

Safari supports a CSS property -webkit-transform that you can script as
follows (rotating the body here but could of course rotate any element):

document.body.style.webkitTransform = 'rotate(31deg)';

Firefox 3.5 supports a similar property -moz-transform:
https://developer.mozilla.org/En/CSS/Using_CSS_transforms
that you could script as element.style.mozTransform.
 
J

Jorge

Safari supports a CSS property -webkit-transform that you can script as
follows (rotating the body here but could of course rotate any element):

document.body.style.webkitTransform = 'rotate(31deg)';

Awesome :)

javascript:(function (a) { setTimeout(function f () { if ((a-=a/8) >
0.05) { document.body.style.webkitTransform = 'rotate('+a+'deg)';
setTimeout(f,0); } else { document.body.style.webkitTransform = 'rotate
(0deg)'; a=360; setTimeout(f,2222); } },0);})(360);

(works in Safari 4)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top