为什么没现象
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script>
function draw(id) {
var ball={x:513,y:100,r:20,g:2,vx:-4,vy:0,color:"red"};
var canvas=document.getElementById(id);
if(canvas==null){
return false;
}
var context=canvas.getContext("2d");
setInterval(
function () {
render(context);
update();
}
,
50
)
}
function update() {
ball.x+=ball.vx;
ball.y+=ball.vy;
ball.vy+=ball.g;
}
function render(cxt) {
context.clearRect(0,0,1024,768);
cxt.fillStyle=ball.color;
cxt.beginPath();
cxt.arc(ball.x,ball.y,ball.r,0,2*Math.PI);
cxt.closePath();
cxt.fill();
}
</script>
</head>
<body onload="draw('canvas')">
<canvas id="canvas" width="1024" height="768">
</canvas>
</body>
</html>