Html5学习--运动且旋转并放大缩小的动画效果

<!DOCTYPE HTML> 
<html>
<head>
<object id="WebBrowser" width=0 height=0 classid="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></object>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
(function(){
	var canvas=null,
	context=null,
	angle=0;
	num=0;
	value=1;
	function resetCanvas(){
		canvas=document.getElementById("simple");
		canvas.width=window.innerWidth;
		canvas.height=window.innerHeight;
		context=canvas.getContext("2d");
	}
	function animate(){
		context.save();
		try{
			//清除画布
			context.clearRect(0, 0, canvas.width, canvas.height);			
			if(num==100){
			value=-1;
			}
			else if(num==0)
			{
			value=1;
			}
			num +=value;
			context.scale(num*1/50,num*1/50)
			//设置原点
			context.translate(canvas.width * 0.5, canvas.height * 0.5);
			//旋转角度
			context.rotate(angle);
			//设置填充颜色
			context.fillStyle = "#FF0000";
			//绘制矩形
			context.fillRect(0, 0, 100, 100);
			angle += 0.05 * Math.PI;
		}
		finally{
			context.restore();
		}
	}
	//当窗口改变时
	$(window).bind("resize",resetCanvas).bind("reorient",resetCanvas);
	$(document).ready(function(){
		window.scrollTo(0,1);
		resetCanvas();
		setInterval(animate,40);
	});
})();
</script>
</script>
</head>
<body>
<canvas id="simple"></canvas>
</body>
</html> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值