html5画布转动实际效果示例

日期:2021-02-25 类型:科技新闻 

关键词:在线小程序开发,微信小程序怎么做店铺,小程序logo设计,小程序平台,小程序码生成

keleyi.htm的编码以下:

拷贝编码
编码以下:

<!DOCTYPE HTML>
<html>
<head>
<title>html转动画布</title>
<script type="text/javascript" src="/jquery⑴.10.2.min.js"></script>
<script type="text/javascript" src="jb51.js"></script>
</head>
<body>
<canvas id="jb51"></canvas>
</body>
</html>

jb51.js的编码以下:

拷贝编码
编码以下:

/*
* 作用:画布转动
*/
(function(){
var canvas=null,
context=null,
angle=0;
function resetCanvas(){
canvas=document.getElementById("jb51");
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);
//设定原点
context.translate(canvas.width * 0.5, canvas.height * 0.5);
//转动角度
context.rotate(angle);
//设定填充色调
context.fillStyle = "#FF0000";
//绘图矩形框
context.fillRect(⑶0, ⑶0, 60, 60);
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);
});
})();