douduikai0562
douduikai0562
2012-09-24 00:35
浏览 118
已采纳

HTML5的Canvas可以处理其中绘制的多个图像吗?

The output page: http://tinyurl.com/9stfo3p The Code: http://tinyurl.com/8wz9krj

Direct Question: Am I approaching this the wrong way, or can HTML5 not handle so many images in one canvas?

Details: I made a script with PhP, HTML5, and Javascript in order to test some code for a dress up feature I wanted to perfect. When I was done, it worked fine. I then started refreshing the page to see how quickly the canvas would load/respond.

Some of the images would fail to show sometimes, and after a few more times of refreshing, nothing would show in the canvas at all.

I decided code this way so I won't have to bother with the GD Library, and if I wanted to add in an Animated Gif, I wouldn't have to do too much to the code (or at least, I don't think I'd have to).

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • dousuitang5239
    dousuitang5239 2012-09-24 01:04
    已采纳

    Canvas can handle as many images in it as you like.

    In your case, I'm seeing an Uncaught TypeError: Cannot call method 'getContext' of null, probably because you are doing window.onload = draw() which is calling the draw method immediately, and before the DOM is ready.

    It should work if you just change it for:

    window.onload = draw;
    

    I've put your code in a fiddle, and you can see it working fine here

    点赞 评论

相关推荐