This paper is the official HTML5 training course for Brother Lian it educational institution, the main introduction: HTML5 Mobile Development Road (10)--online artboard
In this article we use HTML5 to implement an online artboard, played you draw my guess friend today can also do a simple you draw I guess the game, the effect as shown:
The process is straightforward on the code:
[HTML]View PlainCopyprint?
- <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
- <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
- <title> large bowl of dry-mix online artboards </title>
- <script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
- <style type= "Text/css" >
- #php100 {border:1px solid #ccc;}
- </style>
- <body>
- <canvas id= "php100" width= "height=" ></canvas>
- <script type= "Text/javascript" >
- var canvas = document.getElementById (' php100 ');
- var P100=canvas.getcontext ("2d");
- P100.linewidth=5
- P100.strokestyle= "Red";
- var paint=0;
- $ ("#php100"). MouseDown (function (e) {
- var mousex = E.pagex-this.offsetleft;
- var mousey = e.pagey-this.offsettop;
- Paint=1;
- P100.moveto (Mousex,mousey); Start position
- });
- $ ("#php100"). MouseUp (function (e) {
- paint=0;
- });
- $ ("#php100"). MouseMove (function (e) {
- var mousex = E.pagex-this.offsetleft;
- var mousey = e.pagey-this.offsettop;
- if (paint) {
- P100.lineto (Mousex,mousey); Terminating position
- P100.stroke (); End graphic
- }
- });
- </script>
- </body>
Interested friends can expand, add a few buttons to change the color of the artboard or other fun features.
HTML5 Mobile Development Road (10)--online artboard