画布不会清除 [英] Canvas will not clear

查看:120
本文介绍了画布不会清除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了所有可以找到的清晰画布代码,但是当我单击回到画布上时,旧的图形重新出现。我需要它,这样当你按下清除按钮时,图纸不会再回来了。我正在使用paper.js如果有帮助

I have tried every clear canvas code I can find but when I click back onto the canvas, the old drawings reappear. I need it so that when you press the clear button the drawings don't come back on a new draw. I'm using paper.js if that helps

Html

<canvas id="myCanvas" height="400px" width="400px;"></canvas>    

JS(Clearcanvas是一个按钮功能)

JS (Clearcanvas is a function from a button)

function clearcanvas(){

    var c=document.getElementById("myCanvas");
    var ctx=c.getContext("2d");
    ctx.clearRect(0,0,400,400);

    }

绘图功能的JS适用于paper.js

JS for the drawing function works with paper.js

<script type="text/paperscript" canvas="myCanvas">
tool.minDistance = 5;

var path;

function onMouseDown(event) {
path = new Path();
path.strokeColor = 'red';
path.strokeWidth= 3;
path.opacity="0.4";

path.add(event.point, event.point);
}

function onMouseDrag(event) {
path.add(event.point, event.point);
}

function onMouseDrag(event) {
if(event.modifiers.shift) {
    path.lastSegment.point = event.point;
    path.strokeColor = 'blue';

} else {
    path.add(event.point);
}
}    
</script>


推荐答案

你试过这个吗?

 canvas.width = canvas.width;

这篇关于画布不会清除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆