
要清除画布上的图表,请删除<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);
};以上就是如何清除HTML5画布上的图表,以防止触发悬停事件?的详细内容,更多请关注php中文网其它相关文章!
HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号