作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在创建 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++);
}
请帮助我解决上述问题
谢谢问候摩诃
最佳答案
Erik Möller 开发了一个健壮的 polyfill,Paul Irish 现在将其托管在他的 blog post about 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);
};
}());
关于javascript - ie9中报错requestAnimationFrame任何替代解决方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24676874/
我无法在附加行中显示“真”、“假”、"is"和“否”按钮。 我在这里有一个应用程序:Application 请按照以下步骤使用应用程序: 1。当你打开应用程序时,你会看到一个绿色的加号按钮,点击 在此
我是一名优秀的程序员,十分优秀!