Home  >  Article  >  Web Front-end  >  HTML5 canvas rotation effect example_html5 tutorial skills

HTML5 canvas rotation effect example_html5 tutorial skills

WBOY
WBOYOriginal
2016-05-16 15:48:291909browse

The code of

keleyi.htm is as follows:

Copy the code
The code is as follows:




html rotate canvas







The code of jb51.js is as follows:

Copy the code
The code 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 canvas
context.clearRect(0, 0, canvas. width, canvas.height);
//Set the origin
context.translate(canvas.width * 0.5, canvas.height * 0.5);
//Rotate 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 );
});
})();
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn