我有一个问题,需要额外的帮助来解决。具体情况如下:
在Chrome和FF浏览器中,我的小动画很正常(当用户将鼠标悬停在div上时,4个圆同时绘制)。
但是...对于Safari和Opera而言,它们就是不想显示我的动画。我已经查看了错误控制台,得到的消息是:
类型错误:'undefined不是函数(评估'requestAnimationFrame(function {
animate(curPerc / 100)
})')
我不确定这里发生了什么,但我认为'animate'函数正在循环运行,只适用于“hover”函数,并且完成第一次循环后,该函数正在寻找另一个输入,未收到任何输入,从而导致“undefined”错误??虽然我可能完全错了!此外...这并不能解释为什么它在Chrome和FF中有效,而在Safari或Opera中无效。
以下是其中一个圆圈动画的代码,以供参考:
HTML:
<canvas id="myCanvasVD" width="200" height="200"></canvas>
Javascript:
(function() {
var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame ||
window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
window.requestAnimationFrame = requestAnimationFrame;
})();
$(document).ready(function() {
$("#aboutPageDiv").hover(function() {
var myCanvas = document.getElementById('myCanvasVD');
var ctx = myCanvas.getContext("2d");
var x = myCanvas.width / 2;
var y = myCanvas.height / 2;
var radius = 75;
var endPercentVD = 87;
var curPerc = 0;
var counterClockwise = false;
var circ = Math.PI * 2;
var quart = Math.PI / 2;
ctx.lineWidth = 32;
ctx.strokeStyle = '#34c3e5';
ctx.lineCap = "round";
function animate(current) {
ctx.clearRect(0, 0, ctx.width, ctx.height);
ctx.beginPath();
ctx.arc(x, y, radius, -(quart), ((circ) * current) - quart, false);
ctx.stroke();
curPerc++;
if (curPerc < endPercentVD) {
requestAnimationFrame(function () {
animate(curPerc / 100)
});
}
}
animate();
}
);
});
如果有人知道如何在Safari和Opera上使其运行,那真的会很感激,并且一张圣诞卡片将通过邮件送到你手中...
哦,对了,我已经安装了最新版本的Safari和Opera!
非常感谢,
蒂姆