0 Star 0 Fork 0

Pan/html5_canvas

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
6-动画制作.html 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
Pan 提交于 2019-10-15 18:05 . 基础动画
<!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>
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/codingpan/html5_canvas.git
git@gitee.com:codingpan/html5_canvas.git
codingpan
html5_canvas
html5_canvas
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385