简体   繁体   English

HTML5问题<canvas>

[英]Problem with Html5 <canvas>

I have a problem with html5 element. html5元素有问题。 I implemented a canvas and when i enter the site don't run, but when I refresh the page, runs correctly. 我实现了一个画布,但是当我进入网站时却无法运行,但是刷新页面后,它可以正常运行。 Also only runs with Firefox. 也只能在Firefox上运行。 Why I have to refresh and why not in other browsers? 为什么我必须刷新,为什么不用其他浏览器?

The site is: http://www.dendrosite.com 该站点是: http : //www.dendrosite.com

Thanks! 谢谢!

It is because you are drawing images and not necessarily waiting for them to load. 这是因为您正在绘制图像,而不必等待它们加载。

When you refresh, the image is already loaded, so the problem goes away. 刷新时,图像已经加载,因此问题消失了。

From the Mozilla tutorial: Mozilla教程中:

When this script gets executed, the image starts loading. 执行此脚本后,图像开始加载。 Trying to call drawImage before the image has finished loading will throw in gecko 1.9.2 and earlier, and silently do nothing in Gecko 2.0 and later. 在图像加载完成之前尝试调用drawImage会抛出gecko 1.9.2及更早版本,而在Gecko 2.0及更高版本中无提示地执行任何操作。 So you must use an onload event handler: 因此,您必须使用onload事件处理程序:

var img = new Image();   // Create new img element
img.onload = function(){
  // execute drawImage statements here
};
img.src = 'myImage.png'; // Set source path

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM