0

我想每隔 x 秒刷新一次画布而不刷新整个页面。

<script>

$(document).ready(function ()
{
    var odo = new RGraph.Odometer({
        id: 'cvs',
        min: 0,
        max: 360,
        value: <?php echo $windDirDeg; ?>
    }).draw();
 </script>

<body>
 <canvas id="cvs" width="300" height="300"></canvas>
</body>
4

2 回答 2

0

要清除画布,您可以使用 RGraph API:

var ca = document.getElementById('cvs');
RGraph.clear(ca, 'white'); // The colour is optional (the default is transparent)

http://www.rgraph.net/docs/api.html

于 2015-07-16T21:42:54.927 回答
-1

可能是这样的:

x = 3000ms

setInterval(function(){ 
context.clearRect(0, 0, canvas.width, canvas.height);
alert("Canvas cleared"); 
}, 
3000);

完整示例:

<!DOCTYPE html>
<html>
<body>

<canvas id="myCanvas" width="200" height="100" style="border:1px solid #c3c3c3;">
Your browser does not support the HTML5 canvas tag.
</canvas>

<script>
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
setInterval(function(){ 
ctx.clearRect(0, 0, c.width, c.height);
alert("Canvas cleared"); 
}, 
3000);
</script>

</body>
</html>

看这个例子

于 2015-07-16T04:48:54.233 回答