caleb531 / jcanvas

A jQuery plugin that makes the HTML5 canvas easy to work with.
https://projects.calebevans.me/jcanvas/
MIT License
626 stars 192 forks source link

jcanvas21.0.1 in fireFox(70.0.1 ) removeLayer() and removeLayers() has bug #351

Closed 348339749 closed 4 years ago

348339749 commented 4 years ago

jcanvas21.0.1 in fireFox(70.0.1 ) when i use removeLayer() or removeLayers(),i have to move mouse out of canvas, or double click on layer to delete this layer . this is my code: $("canvas").drawPolygon({ fillStyle: "#6c3", x: 100, y: 100, radius: 50, sides: 5, layer:true, click:function(layer){ $("canvas").removeLayer(layer); } });

first click (mousedown,mouseup) nothing change,move out or click again ,the layer will remove.

caleb531 commented 4 years ago

@348339749 You must call drawLayers() after calling removeLayer() to redraw the canvas. So your modified example would become:

$("canvas").drawPolygon({
  fillStyle: "#6c3",
  x: 100, y: 100,
  radius: 50, sides: 5,
  layer:true,
  click:function(layer){
    $("canvas").removeLayer(layer).drawLayers();
  }
});

The reason your code works when you mouse out of the canvas is because jCanvas automatically redraws the canvas upon mouseout. But in this particular instance, you must redraw the canvas manually after removing the layer.