HTML5 Canvas canvas and html5 Canvas

Source: Internet
Author: User

HTML5 Canvas canvas and html5 Canvas

Use html5 canvas elements to draw images on webpages using JavaScript.

Draw a circle by specifying the size, color, and position:

<!DOCTYPE htma>

Draw a line by specifying where to start and where to end

<!DOCTYPE HTML>

Use the color you specified to draw the gradient background

<!DOCTYPE htma>


Place an image on the canvas
<!DOCTYPE HTML>












For canvas clearance issues with HTML5

Yes, it's strange... Why... But it can be opportunistic:

<Body>
<Canvas id = "bo" width = "500" height = "500" style = "border: 1px solid"> your browser does not support secondary applications, update the browser </canvas>
<Input type = "button" onclick = "clea ()" value = "clear"/>
<Script src = "code.jquery.com/jquery-1.6.3.min.js"> </script>
<Script>
Var canvasInit = function (){
Var canvas = document. getElementById ('bo ');
Var pic = canvas. getContext ("2d ");
Pic. lineWidth = 5;
Pic. strokeStyle = "red ";
Var con = false;
$ ("# Bo"). mousedown (function (e ){
Var mouseX = e. pageX-this. offsetLeft;
Var mouseY = e. pageY-this. offsetTop;
Con = true;
Pic. moveTo (mouseX, mouseY );
});
$ ("# Bo"). mouseup (function (e ){
Con = false;
})
$ ("# Bo"). mousemove (function (e ){
Var mouseX = e. pageX-this. offsetLeft;
Var mouseY = e. pageY-this. offsetTop;
If (con)
Pic. lineTo (mouseX, mouseY );
Pic. stroke ();
})
}
CanvasInit ();
Function clea (){
Var tmp = $ ('# Bo'). clone ();
$ ('# Bo'). remove ();
$ ('Body'). prepend (tmp );
CanvasInit ();
// Pic. clearRect (500,500 );
}
</Script>... the remaining full text>

You can draw existing images on the canvas of HTML5.

Pure html5 cannot be done efficiently, but you can use PNG images to first fill all the black parts into transparent

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.