[英]Clear Canvas not working
I have a basic page with a canvas. 我有一个带有画布的基本页面。 In Javascript I run a function after pressing a button that changes the background color and draws a basic rect shape. 在Javascript中,按下按钮会更改背景颜色并绘制基本的矩形形状,然后运行一个函数。
I have a second button though that uses another JS function in order to clean the canvas but it doesn't work. 我有第二个按钮,尽管它使用另一个JS函数来清理画布,但是它不起作用。
function clear() {
var c = document.getElementById("can1");
var ctx = c.getContext("2d");
ctx.clearRect(0, 0, c.width, c.height);
c.style.backgroundColor = white;
}
I have also a codepen-link so that you can see the whole code. 我还有一个Codepen链接,以便您可以查看整个代码。 Codepen page Codepen页面
Thank you in advance. 先感谢您。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.