Javascript cross Browser Rotate
by amindunited
JavaScript
/*
This is not mine!!!!! - copied from "http://kaisarcode.com/javascript-rotate"
*/
/*KaisarCode - Rotate Elements*/
/*
* Rotate elements, even in IExplorer 7.
*
* @Parameters:
* elem [object]: some HTML DOM element.
* deg [number]: value in degrees.
*
* */
//SETUP
function rotate(elem,deg){
var Dx;
var Dy;
var iecos;
var iesin;
var halfWidth;
var halfHeight;
//degrees to radians
var rad=deg*(Math.PI/180);
//get sine and cosine of rotation angle
iecos=Math.cos(rad);
iesin=Math.sin(rad);
//get element's size
halfWidth=elem.offsetWidth/2;
halfHeight=elem.offsetHeight/2;
//calculating position correction values
Dx=-halfWidth*iecos + halfHeight*iesin + halfWidth;
Dy=-halfWidth*iesin - halfHeight*iecos + halfHeight;
//applying CSS3 rotation
elem.style.MozTransform="rotate("+rad+"rad)";
elem.style.WebkitTransform="rotate("+rad+"rad)";
elem.style.OTransform="rotate("+rad+"rad)";
elem.style.MsTransform="rotate("+rad+"rad)";
//rotation Matrix for IExplorer
elem.style.filter="progid:DXImageTransform.Microsoft.Matrix(M11="+iecos+", M12="+-iesin+", M21="+iesin+", M22="+iecos+", Dx="+Dx+", Dy="+Dy+", SizingMethod=auto expand)";
}