使用 Opera 发出 onload() 画布问题

发布于 2024-12-13 18:04:16 字数 1076 浏览 4 评论 0原文

我制作了一个应用程序画布。每次调用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

我做我的改变 2024-12-20 18:04:16

我认为这与缓存的图像以及设置之前的 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 set src. See this article about the problem.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文