即使我使用了MsTransform,以下代码也可以在所有浏览器中使用,但不能在Internet Explorer中使用,但是仍然无法使用。

<!DOCTYPE html>
<html>
<head>
<script>
var looper;
var degrees = 0;
function rotateAnimation(el,speed){
 var elem = document.getElementById(el);
    elem.style.WebkitTransform = "rotate("+degrees+"deg)";
    elem.style.MozTransform = "rotate("+degrees+"deg)";
    elem.style.MsTransform = "rotate("+degrees+"deg)";
    elem.style.OTransform = "rotate("+degrees+"deg)";
looper =
setTimeout(function()
{
    rotateAnimation(el,speed)
},speed);

    degrees++;
     if(degrees > 359){
         degrees = 1;
    }
}
</script>
</head>
<body>
<img id="img1" src="cog1.png" alt="cog1">
<script>rotateAnimation("img1",30);</script>
</body>
</html>

最佳答案

尝试小写:

elem.style.msTransform = "rotate("+degrees+"deg)";


Working Link

08-15 18:33