<tfoot id='F4c96'></tfoot>
      <bdo id='F4c96'></bdo><ul id='F4c96'></ul>

      <i id='F4c96'><tr id='F4c96'><dt id='F4c96'><q id='F4c96'><span id='F4c96'><b id='F4c96'><form id='F4c96'><ins id='F4c96'></ins><ul id='F4c96'></ul><sub id='F4c96'></sub></form><legend id='F4c96'></legend><bdo id='F4c96'><pre id='F4c96'><center id='F4c96'></center></pre></bdo></b><th id='F4c96'></th></span></q></dt></tr></i><div id='F4c96'><tfoot id='F4c96'></tfoot><dl id='F4c96'><fieldset id='F4c96'></fieldset></dl></div>
      1. <legend id='F4c96'><style id='F4c96'><dir id='F4c96'><q id='F4c96'></q></dir></style></legend>
      2. <small id='F4c96'></small><noframes id='F4c96'>

        为什么图像在加载时不显示,但在刷新时显示?

        时间:2023-06-21

          <tfoot id='gx7lQ'></tfoot>
          <legend id='gx7lQ'><style id='gx7lQ'><dir id='gx7lQ'><q id='gx7lQ'></q></dir></style></legend>
            <bdo id='gx7lQ'></bdo><ul id='gx7lQ'></ul>
                  <tbody id='gx7lQ'></tbody>
                  <i id='gx7lQ'><tr id='gx7lQ'><dt id='gx7lQ'><q id='gx7lQ'><span id='gx7lQ'><b id='gx7lQ'><form id='gx7lQ'><ins id='gx7lQ'></ins><ul id='gx7lQ'></ul><sub id='gx7lQ'></sub></form><legend id='gx7lQ'></legend><bdo id='gx7lQ'><pre id='gx7lQ'><center id='gx7lQ'></center></pre></bdo></b><th id='gx7lQ'></th></span></q></dt></tr></i><div id='gx7lQ'><tfoot id='gx7lQ'></tfoot><dl id='gx7lQ'><fieldset id='gx7lQ'></fieldset></dl></div>
                • <small id='gx7lQ'></small><noframes id='gx7lQ'>

                  本文介绍了为什么图像在加载时不显示,但在刷新时显示?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 HTML5 中的 canvas 元素,我注意到一种特殊的行为.在初始加载时,我正在显示的图像不显示.但是,当我刷新浏览器时,它会正确显示.我用过 IE9 和 Chrome.两者的行为相同.JavaScript 代码如下所示:

                  I'm playing with the canvas element in HTML5 and I have noticed a peculiar behavior. On initial load, an image I'm displaying does not show. However, when I refresh the browser, it displays appropriately. I've used IE9 and Chrome. Both behave identically. The JavaScript code looks like this:

                  window.onload = load;
                  function load() {
                      var canvas = document.getElementById("canvas");
                      var context = canvas.getContext("2d");
                      context.fillRect(0, 0, 640, 400);
                      var image = new Image();
                      image.src = "Images/smiley.png";
                      context.drawImage(image, 50, 50);
                  }
                  

                  矩形两次都正确绘制,它是只在浏览器刷新时显示的笑脸.

                  The rectangle draws correctly both times, it's the smiley that only shows on a browser refresh.

                  我正在学习 HTML5 和 JavaScript.我确定我只是在做一些愚蠢的事情,但我无法弄清楚.

                  I'm in the process of learning HTML5 and JavaScript. I'm sure I'm just doing something stupid, but I can't figure it out.

                  推荐答案

                  图片是异步加载的,所以只有在刷新后才加载足够早,因为它是缓存的.通常在您调用 drawImage 时它还没有加载.使用onload:

                  Images load asynchronously, so only after refresh it loads early enough because it's cached. Normally it isn't loaded yet at the time you call drawImage. Use onload:

                  var image = new Image();
                  image.src = "Images/smiley.png";
                  image.onload = function() {
                      context.drawImage(image, 50, 50);
                  };
                  

                  这篇关于为什么图像在加载时不显示,但在刷新时显示?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:使用 pdf.js 和 ImageData 将 .pdf 渲染到单个 Canvas 下一篇:Fabric.js 的文本框不换行

                  相关文章

                  • <bdo id='L79Dy'></bdo><ul id='L79Dy'></ul>
                  <i id='L79Dy'><tr id='L79Dy'><dt id='L79Dy'><q id='L79Dy'><span id='L79Dy'><b id='L79Dy'><form id='L79Dy'><ins id='L79Dy'></ins><ul id='L79Dy'></ul><sub id='L79Dy'></sub></form><legend id='L79Dy'></legend><bdo id='L79Dy'><pre id='L79Dy'><center id='L79Dy'></center></pre></bdo></b><th id='L79Dy'></th></span></q></dt></tr></i><div id='L79Dy'><tfoot id='L79Dy'></tfoot><dl id='L79Dy'><fieldset id='L79Dy'></fieldset></dl></div>

                  <legend id='L79Dy'><style id='L79Dy'><dir id='L79Dy'><q id='L79Dy'></q></dir></style></legend>
                  1. <tfoot id='L79Dy'></tfoot>

                      <small id='L79Dy'></small><noframes id='L79Dy'>