如何清除HTML5画布上的图表,以防止触发悬停事件?

原创
ithorizon 5个月前 (10-19) 阅读数 38 #HTML

要清除画布上的图表,请删除元素,然后将一个新的元素附加到父容器中,如下所示的代码:

var resetCanvas = function(){
   $('#results-graph').remove();  
   $(&#39;#graph-container&#39;).append(&#39;<canvas id = "results-graph"><canvas>&#39;);
   canvas = document.querySelector(&#39;#results-graph&#39;);

   ct = canvas.getContext(&#39;2d&#39;);
   ct.canvas.width = $(&#39;#graph&#39;).width(); // here we are resizing the new canvas element to parent width
   ct.canvas.height = $(&#39;#graph&#39;).height(); // here we are resizing the new canvas element to parent height
   var a = canvas.width/2;
   var b = canvas.height/2;

   ct.font = &#39;12pt Calibri&#39;;
   ct.textAlign = &#39;Align Left&#39;;
   ct.fillText(&#39;left aligned text on the canvas&#39;, a, b);
};

以上就是如何清除HTML5画布上的图表,以防止触发悬停事件?的详细内容,更多请关注IT视界其它相关文章!



热门