JavaScript Simple Artboard

Source: Internet
Author: User

HTML 5 canvas is just a container that wants to draw everything that relies on javascript. It feels like nothing can be separated from this JavaScript script.

Simple Artboard Core code:

<Script>        varStart= false;//does the draw switch start?window.onload= function(){            varCVS=document.getElementById ("CVS"); varCXT=Cvs.getcontext ("2d"); //Mouse presses on the artboardCvs.onmousedown= function(){                //1. Get the coordinates of the mouse                varx=Event.offsetx; vary=event.offsety; //2. Move the brush to the current positionCxt.moveto (x, y); //3. Turn on the draw switchStart= true; //4. Get and set the brush color                varColor=document.getElementById ("Color"). Value; Cxt.strokestyle=color; //5. Reset the pathCxt.beginpath (); //6. Block Default ProgramsEvent.preventdefault (); }            //Mouse moves on the artboardCvs.onmousemove= function(){                if(start) {//1. Get the new coordinates of the mouse                    varx=Event.offsetx; vary=event.offsety; //2. Draw the line to that positionCxt.lineto (x, y);                Cxt.stroke (); }                            }            //Mouse ReleaseCvs.onmouseup= function(){                //1. Turn off the draw switchStart= false; //2. Close the path of the brushCxt.closepath (); }            //move the mouse out of the artboardCvs.onmouseout= function(){                //1. Turn off the draw switchStart= false; //2. Close the path of the brushCxt.closepath (); }        }  </Script>

As follows:

JavaScript Simple 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.