如何从HTML5画布中清除图表,以使悬停事件无法触发?
要从画布上清除图表,请删除<canvas>元素,然后将新的<canvas>元素附加到父容器,如下面的代码所示-
var resetCanvas = function(){
$('#results-graph').remove();
$('#graph-container').append('<canvas id = "results-graph"><canvas>');
canvas = document.querySelector('#results-graph');
ct = canvas.getContext('2d');
ct.canvas.width = $('#graph').width(); // here we are resizing the new canvas element to parent width
ct.canvas.height = $('#graph').height(); // here we are resizing the new canvas element to parent height
var a = canvas.width/2;
var b = canvas.height/2;
ct.font = '12pt Calibri';
ct.textAlign = 'Align Left';
ct.fillText('left aligned text on the canvas', a, b);
};热门推荐
10 花茶礼盒生日祝福语简短
11 幼儿篮球祝福语大全简短
12 洁字谐音祝福语简短
13 作者签名祝福语大全简短
14 生日朋友惊喜祝福语简短
15 婆婆蛋糕祝福语简短英文
16 新年导员祝福语简短
17 晚辈读大学祝福语简短
18 搞笑舞蹈生日祝福语简短