Change background image in HTML5 canvas

前提是你 提交于 2020-01-07 02:18:09

问题


I need to change background image in HTML5 canvas.

I want to use 2 different thumbnails as buttons and when I click on one of the images the background should be change to that particular image.


回答1:


Technique 1

  1. On click of the appropriate buttons set a unique CSS class on your <canvas> element.
  2. Use CSS to apply a background image to your canvas.

Drawing commands and erasing your canvas will not affect the CSS-applied background image behind your content.

Technique 2

  1. Write a redraw() function that knows how to erase the canvas and regenerate your drawing, including determining what image to draw as the background first.
  2. On click of the buttons set a variable and re-invoke your redraw() function. It will erase your canvas and use the variable to draw the correct image.


来源:https://stackoverflow.com/questions/9688173/change-background-image-in-html5-canvas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!