您可以使用cssSandpaper来使用transform属性,该属性可用于旋转Gecko(Firefox),WebKit(Safari,Chrome),Opera甚至Internet Explorer中的元素。
element
//
// - DIV position must be absolute or relative
// - Will use the center point of DIV as origin for tilt
//
// I think it will work on most browsers (including ie6, ie7 & ie8)
//
function divRotate( divObj, divTop, divLeft, divHeight, divWidth, newAngleDeg )
{
var radAngle = Math.PI * newAngleDeg / 180;
var spinAngle = radAngle;
if ( window.navigator.userAgent.indexOf ( &#39;MSIE &#39; ) <&#61; 0 || typeof document.documentElement.style.opacity!&#61;&#39;undefined&#39; )
radAngle &#61; -radAngle;
var sinAngle &#61; parseFloat(parseFloat(Math.sin(radAngle)).toFixed(8));
var cosAngle &#61; parseFloat(parseFloat(Math.cos(radAngle)).toFixed(8));
var m11 &#61; cosAngle;
var m12 &#61; -sinAngle;
var m21 &#61; sinAngle;
var m22 &#61; cosAngle;
if ( window.navigator.userAgent.indexOf ( &#39;MSIE &#39; ) <&#61; 0 || typeof document.documentElement.style.opacity!&#61;&#39;undefined&#39; )
{
divObj.style.WebkitTransform &#61; &#39;matrix(&#39;&#43; m11 &#43;&#39;,&#39;&#43; m12 &#43;&#39;,&#39;&#43; m21 &#43;&#39;,&#39;&#43; m22 &#43;&#39;,&#39; &#43; 0 &#43; &#39;,&#39; &#43; 0 &#43; &#39;)&#39;;
divObj.style.MozTransform &#61; &#39;matrix(&#39;&#43; m11 &#43;&#39;,&#39;&#43; m12 &#43;&#39;,&#39;&#43; m21 &#43;&#39;,&#39;&#43; m22 &#43;&#39;,&#39; &#43; 0 &#43; &#39;px,&#39; &#43; 0 &#43; &#39;px)&#39;;
divObj.style.msTransform &#61; &#39;matrix(&#39;&#43; m11 &#43;&#39;,&#39;&#43; m12 &#43;&#39;,&#39;&#43; m21 &#43;&#39;,&#39;&#43; m22 &#43;&#39;,&#39; &#43; 0 &#43; &#39;,&#39; &#43; 0 &#43; &#39;)&#39;;
divObj.style.OTransform &#61; &#39;matrix(&#39;&#43; m11 &#43;&#39;,&#39;&#43; m12 &#43;&#39;,&#39;&#43; m21 &#43;&#39;,&#39;&#43; m22 &#43;&#39;,&#39; &#43; 0 &#43; &#39;,&#39; &#43; 0 &#43; &#39;)&#39;;
divObj.style.transform &#61; &#39;matrix(&#39;&#43; m11 &#43;&#39;,&#39;&#43; m12 &#43;&#39;,&#39;&#43; m21 &#43;&#39;,&#39;&#43; m22 &#43;&#39;,&#39; &#43; 0 &#43; &#39;,&#39; &#43; 0 &#43; &#39;)&#39;;
divObj.style.top &#61; divTop &#43; &#39;px&#39;;
divObj.style.left &#61; divLeft &#43; &#39;px&#39;;
return;
}
var sinSpinAngle &#61; -parseFloat(parseFloat(Math.sin(-spinAngle)).toFixed(8));
var cosSpinAngle &#61; parseFloat(parseFloat(Math.cos(-spinAngle)).toFixed(8));
var sinAnglePerp &#61; parseFloat(parseFloat(Math.sin(radAngle-Math.PI)).toFixed(8));
var cosAnglePerp &#61; parseFloat(parseFloat(Math.cos(radAngle-Math.PI)).toFixed(8));
var halfHeight &#61; divHeight/2;
var halfWidth &#61; divWidth/2;
var radius &#61; Math.sqrt(halfHeight*halfHeight &#43; halfWidth*halfWidth);
var ulx &#61; divLeft &#43; halfWidth - radius*cosSpinAngle &#43; sinAnglePerp*halfHeight;
var uly &#61; divTop &#43; halfHeight - radius*sinSpinAngle &#43; cosAnglePerp*halfHeight;
var urx &#61; radius*cosSpinAngle &#43; divLeft &#43; halfWidth &#43; sinAnglePerp*halfHeight;
var ury &#61; radius*sinSpinAngle &#43; divTop &#43; halfHeight &#43; cosAnglePerp*halfHeight;
var lrx &#61; radius*cosSpinAngle &#43; divLeft &#43; halfWidth - sinAnglePerp*halfHeight;
var lry &#61; radius*sinSpinAngle &#43; divTop &#43; halfHeight - cosAnglePerp*halfHeight;
var llx &#61; divLeft &#43; halfWidth - radius*cosSpinAngle - sinAnglePerp*halfHeight;
var lly &#61; divTop &#43; halfHeight - radius*sinSpinAngle - cosAnglePerp*halfHeight;
divObj.style.filter &#61; "filter: progid:DXImageTransform.Microsoft.Matrix( M11&#61;"&#43;m11&#43;", M12&#61;"&#43;m12&#43;", M21&#61;"&#43;m21&#43;", M22&#61;"&#43;m22&#43;", sizingMethod&#61;&#39;auto expand&#39; );";
var spinTop &#61; Math.min( uly, ury, lry, lly );
var spinRight &#61; Math.max( ulx, urx, lrx, llx );
var spinBottom &#61; Math.max( uly, ury, lry, lly );
var spinLeft &#61; Math.min( ulx, urx, lrx, llx );
divObj.style.top &#61; spinTop &#43; &#39;px&#39;;
divObj.style.right &#61; spinRight &#43; &#39;px&#39;;
divObj.style.bottom &#61; spinBottom &#43; &#39;px&#39;;
divObj.style.left &#61; spinLeft &#43; &#39;px&#39;;
}
答案 3 :(得分&#xff1a;0)