我在HTML5中有一个画布,正在制作一个网络绘画应用程序。但是,当其他客户端收到绘图代码时,它不会绘制到画布上,直到他们将鼠标移到画布上。
有没有办法解决这个问题?我希望绘图出现并更新到其他客户端,而不必将鼠标光标放在画布上。
发布于 2012-06-04 06:24:17
来自https://developer.mozilla.org/en/Drawing_Graphics_with_Canvas
<html>
<head>
<script type="application/javascript">
var drawHandle;
function draw() {
return drawHandle = setTimeout(function(){
var canvas = document.getElementById("canvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "red";
ctx.beginPath();
ctx.moveTo(30, 30);
ctx.lineTo(150, 150);
// was: ctx.quadraticCurveTo(60, 70, 70, 150); which is wrong.
ctx.bezierCurveTo(60, 70, 60, 70, 70, 150); // <- this is right formula for the image on the right ->
ctx.lineTo(30, 30);
ctx.fill();
}
}, 1000);//Where 1000 is the timeout in milliseconds
</script>
</head>
<body onload="draw()">
<canvas id="canvas" width="300" height="300"></canvas>
</body>
</html>https://stackoverflow.com/questions/10874331
复制相似问题