39,084
社区成员
发帖
与我相关
我的任务
分享
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<title> 页面名称 </title>
</head>
<body>
<canvas id="canvasId" width="400" height="350"></canvas>
<script type="text/javascript">
var canvas = document.getElementById("canvasId");
var ctx = canvas.getContext("2d");
var x = 400, y = 300;
function run() {
ctx.clearRect(0,0,canvas.width,canvas.height);
ctx.beginPath();
ctx.moveTo(x,y);
ctx.lineTo(x-100,y-50);
ctx.stroke();
x-=2;
y-=1;
if (x>150) {
setTimeout(run, 16);
}
}
run();
</script>
</body>
</html>