HTML graffiti function, and data transfer to the background

Source: Internet
Author: User

var C=document.getelementbyid ("MyCanvas"), Var cxt=c.getcontext ("2d"), cxt.linewidth=5;cxt.strokestyle= "#000000"; cxt.lock=false;$ ("#myCanvas"). MouseDown (function (e) {cxt.beginpath ();//Clear empty path cxt.lock=true;var Mousepos = Getmousepos (c, E); Cxt.moveto (MOUSEPOS.X,MOUSEPOS.Y); This.setcapture && this.setcapture (); return false;// document.getElementById ("Xycoordinates"). innerhtml= "Coordinates: (" + x + "," + y + ")";} "; Document.onmousemove = function (e) {if (Cxt.lock) {var mousepos = Getmousepos (c, e); var x=mousepos.x;var y=mousepos.y; Cxt.lineto (x, y); Cxt.stroke (); return false;}} $ ("Body"). MouseUp (function (e) {cxt.lock=false;cxt.closepath ();//closed path return true;//document.getElementById (" Xycoordinates "). innerhtml=" Coordinates: ("+ x +", "+ y +") ";}"; $ ("#submitimage"). Click (function () {$ ("#imageurl"). Val (C.todataurl ());}); /canvas Mouse positioning function Getmousepos (canvas, evt) {var rect = Canvas.getboundingclientrect (); return {x:evt.clientx- Rect.left * (canvas.width/rect.width), Y:evt.clienty-reCt.top * (canvas.height/rect.height)}}//color value var = new Array ("#000000", "#0066FF", "#6600FF", "#993366", "#33CC66", "#FF3300"); for (var i=0; $ ("#selectcolor li"). EQ (i). Val () ==0;i++) {$ ("#selectcolor li"). EQ (i). CSS ("Background-color" , Color[i]);} Color Select $ ("#selectcolor li"). Click (function () {cxt.strokestyle=$ (this). CSS ("BackgroundColor");}); /Brush Size $ ("#pensize li"). Click (function () {if (this). Text () = = "Thin") {cxt.linewidth=5;} else if ($ (this). Text () = = "Medium") {cxt.linewidth=10;} else{cxt.linewidth=15;}}); $ ("#canvasreset"). Click (function () {cxt.clearrect (0, 0, c.width, c.height);//Clear the canvas, the upper left corner is the start});

  

HTML graffiti function, and data transfer to the background

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.