HTML5 Canvas 图像动画的实现(实例小球弹跳)
来源:互联网 发布:至尊宝到底爱谁知乎 编辑:程序博客网 时间:2024/04/29 08:13
Canvas 中 clearRect 清除函数
var c=document.getElementById("php100");
var p100=c.getContext("2d");
p100.clearRect(x,y,x,y)// 擦除画布一个区域x-y、x-y
------
代码如下:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<canvas id="php100" width="500" height="200"></canvas>
<div id="ds"></div>
<script type="text/javascript">
var canvas = document.getElementById("php100");
var p100 = canvas.getContext("2d");
var dir = 100;
var height = 500;
var width = 300;
var exp = 1;//像素移动的位置
function fff()
{
p100.clearRect(0,0,height,width);//清除上一次的痕迹
p100.fillStyle = "red";
p100.beginPath();
p100.arc(190, dir, 20, 0, Math.PI * 2, 1);
p100.closePath();
p100.fill();
dir = dir + exp;
if(dir==0||dir==height)
{
exp = exp * -1;
}
}
</script>
<button onclick="tt=setInterval(fff,70);">开始</button>
<button onclick="clearInterval(tt);" >停止</button>
</body>
</html>
- HTML5 Canvas 图像动画的实现(实例小球弹跳)
- HTML Canvas实例 曲线弹跳的小球
- 利用canvas画布制作小球弹跳动画
- HTML5 Canvas 图像动画的实现
- 实例学习:弹跳的小球
- 弹跳动画的实现
- canvas实现多个弹跳小球 js部分
- canvas例子一弹跳小球
- canvas demo-小球弹跳游戏
- 弹跳的小球
- HTML5 Canvas 基于OO的动画实例
- html5 canvas实现小球绕圆旋转
- html5 canvas 实现小球绕椭圆旋转
- HTML5 Canvas 逐帧动画的实现
- HTML5 Canvas 逐帧动画的实现
- HTML5 Canvas 逐帧动画的实现
- JAVA 多线程 经典实例-弹跳小球
- HTML5重力感应小球冲撞动画实现
- spring随笔
- Setup Factory打包 自己的DLL文件注册,检查vc++ 2008运行库
- Leetcode 4 Median of Two Sorted Arrays
- 线程与进程
- 神经网络编程入门
- HTML5 Canvas 图像动画的实现(实例小球弹跳)
- rac快速部署要点部分
- hdu 4710
- delphi 打开文件
- android 杀死进程的方法总结
- JS生成Guid字符串
- 浅析LinkedList及其应用
- android 4.1 UI 工具测试的新利器, uiautomator
- ios tableView那些事 (十五)用故事模式自定义cell