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

HTML5 canvas rotation effect example_html5 tutorial skills

WBOY
Release: 2016-05-16 15:48:29
Original
1939 people have browsed it

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 );
});
})();
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template