HTML5 Mobile Development Road (10)--online artboard

Source: Internet
Author: User

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?
  1. <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
  2. <meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
  3. <title> large bowl of dry-mix online artboards </title>
  4. <script src= "Http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
  5. <style type= "Text/css" >
  6. #php100 {border:1px solid #ccc;}
  7. </style>
  8. <body>
  9. <canvas id= "php100" width= "height=" ></canvas>
  10. <script type= "Text/javascript" >
  11. var canvas = document.getElementById (' php100 ');
  12. var P100=canvas.getcontext ("2d");
  13. P100.linewidth=5
  14. P100.strokestyle= "Red";
  15. var paint=0;
  16. $ ("#php100"). MouseDown (function (e) {
  17. var mousex = E.pagex-this.offsetleft;
  18. var mousey = e.pagey-this.offsettop;
  19. Paint=1;
  20. P100.moveto (Mousex,mousey); Start position
  21. });
  22. $ ("#php100"). MouseUp (function (e) {
  23. paint=0;
  24. });
  25. $ ("#php100"). MouseMove (function (e) {
  26. var mousex = E.pagex-this.offsetleft;
  27. var mousey = e.pagey-this.offsettop;
  28. if (paint) {
  29. P100.lineto (Mousex,mousey); Terminating position
  30. P100.stroke (); End graphic
  31. }
  32. });
  33. </script>
  34. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.