【发布时间】:2015-08-30 23:10:44
【问题描述】:
我正在使用 html5 画布,但它无法正常工作
<section class="row" style="margin: 0px auto;">
<canvas id="a" width=1000 height=350></canvas>
<canvas id="b" width=1000 height=350></canvas>
<canvas id="c" width=1000 height=350></canvas>
<canvas id="d" width=1000 height=350></canvas>
<canvas id="e" width=1000 height=350></canvas>
<canvas id="f" width=1000 height=350></canvas>
<canvas id="g" width=1000 height=350></canvas>
<canvas id="h" width=1000 height=350></canvas>
<canvas id="i" width=1000 height=350></canvas>
<img src="original.png" class="ogimg" id="ogimg"/>
<img src="shadow.png" class="high" id="high"/>
<img src="bulldozer-mocha.png" name="bulldozer-mocha.png" onclick="drw(this)">
<img src="bulldozer.png" name="bulldozer.png" onclick="drw_cushion(this)">
<img src="mocha.png" name="mocha.png" onclick="drw_cushions(this)">
</section>
完整代码在这里jsfiddle
代码可以正常工作,但需要 2 或 3 次页面刷新
请帮我找出错误
【问题讨论】:
-
什么工作不正常?你试图做什么,发生了什么/没有发生什么?我们需要比“不工作”更多的信息,因为这是主观的并且可能意味着任何事情。
-
它需要多次点击和页面刷新才能开始工作
-
功能正常工作,检查警告信息,但认为需要双击在画布上绘制图像
-
那么每个画布首先应该做什么?预期的行为是什么?您没有提供足够的信息让任何人提供答案。
-
在尝试绘制图像之前,您没有给图像加载时间。您必须通过设置 image.onload 回调给您的图像加载时间。看看这篇文章:stackoverflow.com/questions/30578521/…。您可能希望在应用程序开始时预加载所有图像,以便在需要时可用。看看这篇文章:stackoverflow.com/questions/23220385/…
标签: javascript jquery html performance html5-canvas