我遇到了问题.rect()
。我已经使用创建了一个网格,.drawImage(canvas...)
并且每当 I 时.stroke()
,它都会再次出现。我怎样才能完全删除那个矩形?
问候
var canvas = document.getElementById('board');
var context = canvas.getContext('2d'),
wt = canvas.width,
ht = canvas.height;
canvas.onmousedown = function (e) {
e.preventDefault(); // disabling selecting
context.strokeStyle = "red";
context.lineWidth = 1;
context.rect(wt / 2 - 50, ht / 2 - 100, 100, 200);
context.fillText("<- why is it here? didn't \"clearRect()\" delete it?", 8, 8);
context.stroke();
};
function grid() {
var h = 2.5,
p = 2.5;
context.rect(0.5, 0.5, 5, 5);
context.strokeStyle = "#f0f0f0";
context.stroke(); // creating a 5x5 small rectangle in top left corner
for (i = 0; i < wt; i += p) {
p *= 2;
context.drawImage(canvas, p, 0); // replicating it horizontally...
}
for (i = 0; i < ht; i += h) {
h *= 2;
context.drawImage(canvas, 0, h); // ... and vertically
}
context.clearRect(0, 0, 5, 5); // here I am deleting that stroke, because I don't need it anymore
context.drawImage(canvas, 0, 55, 5.5, 5.5, 0, 0, 5.5, 5.5); // drawing it with drawImage();
}
grid();