The content of translate.html is as follows:
[Html]
<! Doctype html>
<Html>
<Head>
<Script type = "text/javascript" src = "jquery-1.7.2.min.js"> </script>
<Script type = "text/javascript" src = "translate. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
});
</Script>
</Head>
<Body>
<Canvas id = "simple"> </canvas>
</Body>
</Html>
<! Doctype html>
<Html>
<Head>
<Script type = "text/javascript" src = "jquery-1.7.2.min.js"> </script>
<Script type = "text/javascript" src = "translate. js"> </script>
<Script type = "text/javascript">
$ (Document). ready (function (){
});
</Script>
</Head>
<Body>
<Canvas id = "simple"> </canvas>
</Body>
</Html>
The code for translate. js is as follows:
[Javascript]
(Function (){
Var canvas = null,
Context = null,
Angle = 0;
Function resetCanvas (){
Canvas = document. getElementById ("simple ");
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 the fill color
Context. fillStyle = "# FF0000 ";
// Draw a 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 );
});
})();
(Function (){
Var canvas = null,
Context = null,
Angle = 0;
Function resetCanvas (){
Canvas = document. getElementById ("simple ");
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 the fill color
Context. fillStyle = "# FF0000 ";
// Draw a 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 );
});
})();
Open translate.html with a browser supporting hmtl5to see a red circle