HTML5 Canvas Animation With RequestAnimFrame
HTML5 Canvas Animation With RequestAnimFrame
- <html>
- <head>
- <style>
- body{
- magin:0px;
- padding:0px;
- }
- </style>
- </head>
- <body>
- <canvas id="mycanvas" width="500" height="250">
- <script>
- window.requestAnimFrame = (function(callback)){
- return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || window.oRequestAnimationFrame || window.msRequestAnimationFrame ||
- function(callback){
- window.setTimeout(callback, 1000/60);
- };
- })();
- function animation(){
- var canvas = document.getElementById('MyCanvas');
- var context = canvas.getContext('2d');
- context.clearRect(0, 0, canvas.width, canvas.height);
- requestAnimFrame(function(){
- animation();
- });
- }
- animation();
- </script>
- </body>
- </html>
No comments:
Post a Comment