在ie9中错误requestAnimationFrame任何替代解决方案

我正在创建Canvas(我是这个Canvas的新手)对象圆柱体,这工作得很好Chrome和Firefox,但是当我在ie9中打开相同的文件时。

由于'requestAnimationFrame'是未定义的,因此出现错误

当我谷歌错误它说requestAniationFrame不会在ie9上工作。

任何机构都可以帮助我解决这个问题吗?

这是我的代码

var canvas = document.getElementById("canvas");
        var context = canvas.getContext("2d");

        var degreeAngle = 0;
        requestAnimationFrame(animate);

        function drawRotatedCylinder(x, y, w, h, degreeAngle) {
            context.save();
            context.translate(x + w / 10, y + h / 10);
            context.rotate(degreeAngle * Math.PI / 180);
            drawCylinder(-w / 10, -h / 10, w, h);
            context.restore();
        }   
function animate() {
        //requestAnimationFrame(animate);
        context.clearRect(0, 0, canvas.width, canvas.height);
        drawRotatedCylinder(100, 100, 180, 180, degreeAngle++);
}

请帮助我解决上述问题

感谢问候玛哈


ErikMöller开发了一个强大的polyfill,Paul Irish在他的博客中发布了关于requestAnimationFrame的文章。 如果你使用这段代码,你可以透明地在任何浏览器中使用requestAnimationFrame:

(function() {
    var lastTime = 0;
    var vendors = ['webkit', 'moz'];
    for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
        window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
        window.cancelAnimationFrame =
          window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
    }

    if (!window.requestAnimationFrame)
        window.requestAnimationFrame = function(callback, element) {
            var currTime = new Date().getTime();
            var timeToCall = Math.max(0, 16 - (currTime - lastTime));
            var id = window.setTimeout(function() { callback(currTime + timeToCall); },
              timeToCall);
            lastTime = currTime + timeToCall;
            return id;
        };

    if (!window.cancelAnimationFrame)
        window.cancelAnimationFrame = function(id) {
            clearTimeout(id);
        };
}());
链接地址: http://www.djcxy.com/p/89935.html

上一篇: Error requestAnimationFrame in ie9 any alternate solution

下一篇: MP3 either plays or fails to play in IE9 and Firefox HTML5