代码拉取完成,页面将自动刷新
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<canvas id="canvas" width="400" height="400"></canvas>
<div>
<button id="start">start</button>
<button id="stop">stop</button>
</div>
<script src="jq.js"></script>
<script>
var canvas = document.getElementById('canvas'),
context = canvas.getContext('2d'),
play = true,
start = document.getElementById('start'),
stop = document.getElementById('stop')
//创建用于控制动画的按钮
$(start).hide().click(function(){
$(this).hide()
$(stop).show()
play = true
animate()
})
$(stop).click(function(){
$(this).hide()
$(start).show()
play = false
})
//运动的正方形
var x = 0,
direction = 10
function animate(){
if(play){
x+=direction
if(x >= canvas.width){
direction = -10
} else if(x<=0){
direction = 10
}
context.clearRect(0,0,canvas.width, canvas.height)
context.fillRect(x,250,10,10)
setTimeout(animate, 1000/60)
}
}
animate()
</script>
</body>
</html>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。