Comment: This article introduces an example of the canvas rotation effect that JS and html5 can be used.
The code of keleyi.htm is as follows:
<!DOCTYPE HTML>
<html>
<head>
<title>html Rotating Canvas</title>
<script type="text/javascript" src="/jquery-1.10.2.min.js"></script>
<script type="text/javascript" src="jb51.js"></script>
</head>
<body>
<canvas></canvas>
</body>
</html>
The code of jb51.js is as follows:
/*
* Function: Canvas rotation
*/
(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{
//Clear the canvas
context.clearRect(0, 0, canvas.width, canvas.height);
//Set the origin
context.translate(canvas.width * 0.5, canvas.height * 0.5);
//Rotation angle
context.rotate(angle);
//Set fill color
context.fillStyle = "#FF0000";
//Draw rectangle
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);
});
})();