以下代码适用于所有浏览器,但不适用于Internet Explorer,即使我使用的是MsTransform,但它仍无效。
<!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>