keleyi.htm的代码如下:
1 2 3 4html旋转画布-柯乐义 5 6 7 8 9 10 11
keleyi.js的代码如下:
1 /* 2 * 功能:画布旋转 3 * http://keleyi.com 4 * 柯乐义 copyright 5 */ 6 (function(){ 7 var canvas=null, 8 context=null, 9 angle=0;10 function resetCanvas(){11 canvas=document.getElementById("ke"+"leyi");12 canvas.width=window.innerWidth;13 canvas.height=window.innerHeight;14 context=canvas.getContext("2d");15 }16 function animate(){17 context.save();18 try{19 //清除画布20 context.clearRect(0, 0, canvas.width, canvas.height);21 //设置原点22 context.translate(canvas.width * 0.5, canvas.height * 0.5);23 //旋转角度24 context.rotate(angle);25 //设置填充颜色26 context.fillStyle = "#FF0000";27 //绘制矩形28 context.fillRect(-30, -30, 60, 60);29 angle += 0.05 * Math.PI;30 }31 finally{32 context.restore();33 }34 }35 $(window).bind("resize",resetCanvas).bind("reorient",resetCanvas);36 $(document).ready(function(){37 window.scrollTo(0,1);38 resetCanvas();39 setInterval(animate,40);40 });41 })();