当前位置: 移动技术网 > IT编程>网页制作>Html5 > html5画布旋转效果示例

html5画布旋转效果示例

2019年07月25日  | 移动技术网IT编程  | 我要评论

keleyi.htm的代码如下:

复制代码
代码如下:

<!doctype html>
<html>
<head>
<title>html旋转画布</title>
<script type="text/javascript" src="/jquery-1.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(-30, -30, 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);
});
})();

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网