使用 Opera 发出 onload() 画布问题
我制作了一个应用程序画布。每次调用draw()函数时,都会在画布上绘制多个图像。问题是 Opera 不起作用。 Onload 功能并不总是有效。
function draw(){
ctx.clearRect (0, 0, canvas.width, canvas.height);
var img = new Image();
img.src = srcvolets;
img.onload = function(){
ctx.drawImage(img, 0, 0,canvas.width,canvas.height);
if(srccouleur!=null){
var img2 = new Image();
img2.src = 'images/couleurs/'+volets+'/'+srccouleur+'.png';
img2.onload = function(){
ctx.drawImage(img2, 0, 0,canvas.width,canvas.height);
if(srcsculpture!=null){
var img3 = new Image();
img3.src = cheminsculpt+srcsculpture;
img3.onload = function(){
if(volets=='furno'){
ctx.drawImage(img3, 175, 235);
}else{
ctx.drawImage(img3, 175, 242);
}
}
}
}}}}
谢谢。 (对不起我的英语,我说法语)
I make an application canvas. Every time I call draw () function, multiple images are drawn in canvas. The problem is that with Opera it does not work. Onload function does not always work.
function draw(){
ctx.clearRect (0, 0, canvas.width, canvas.height);
var img = new Image();
img.src = srcvolets;
img.onload = function(){
ctx.drawImage(img, 0, 0,canvas.width,canvas.height);
if(srccouleur!=null){
var img2 = new Image();
img2.src = 'images/couleurs/'+volets+'/'+srccouleur+'.png';
img2.onload = function(){
ctx.drawImage(img2, 0, 0,canvas.width,canvas.height);
if(srcsculpture!=null){
var img3 = new Image();
img3.src = cheminsculpt+srcsculpture;
img3.onload = function(){
if(volets=='furno'){
ctx.drawImage(img3, 175, 235);
}else{
ctx.drawImage(img3, 175, 242);
}
}
}
}}}}
Thank you. (Sorry for my English, I speak French)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这与缓存的图像以及设置之前的 onload 触发有关。
您可能需要在设置
src
之前尝试设置onload
。请参阅这篇有关该问题的文章。I think this has to do with images being cached, and the
onload
firing before it is set.You might need to try setting
onload
before you setsrc
. See this article about the problem.