Classic! HTML5 Canvas simulates the fragable fabric effect, html5canvas

Source: Internet
Author: User

Classic! HTML5 Canvas simulates the fragable fabric effect, html5canvas

This is an HTML5 Canvas application demonstration that simulates the effect of torn fabric. You will see thatCanvasWith the powerful drawing and animation functions, you can achieve the effect with little code.

Tip: to ensure the best results, visit modern browsers such as IE10 +, Chrome, Firefox, and Safari.

 

 

Demo of source code download

 

Articles you may be interested in
  • 10 useful results in Web development [Source Code download]
  • Excellent jQuery Ajax paging plug-ins and tutorials carefully selected
  • 12 amazing creative 404 error page Designs
  • Let the website get started! 12 excellent jQuery animation plug-ins
  • Amazing 8 HTML5 & JavaScript Special Effects

 

Link to this article: Classic effect! HTML5 Canvas simulates the effect of torn fabric

Source: Dream sky ◆ focus on front-end development technology ◆ share web design resources


Canvas in Html5: I set the size of the Canvas to 100*304 PX, but it changed to * 154px during browser preview?

Parent:
Set the length and width of the canvas as follows: <canvas width = "100" height = "100"> </canvas>

Remove the # nh {width: 100; height: 100;} css settings.

Tip:
1. Another point is that when setting css, a unit is required for the length and width, for example, # nh {width: 100px; height: 100px ;}

2. js statements. Add semicolons to the backend to form a good habit.

How does the HTML5 canvas lineTO () method draw lines of different thicknesses and colors in the same canvas?

Var canvasDom = $ ("myCanvas ");
Var myDraw1 = new Draw (canvasDom );
$ ("Button_line"). onclick = function (){
CanvasDom. onmousemove = function (e ){
MyDraw1.drawLine (e );
}
}
$ ("Button_line_width"). onclick = function (){
MyDraw1.setLineWidth ($ ("text_line_width"). value );
}
$ ("Button_choose_color"). onclick = function (){
MyDraw1.chooseColor ($ ("text_choose_color"). value );
}
Function Draw (canvasDom ){
Var mouseX, mouseY, mx, my;
Var pd = false;
Var coordinate = function (e ){
MouseX = e. pageX-canvasDom.offsetLeft;
MouseY = e. pageY-canvasDom.offsetTop;
}
CanvasDom. onmousedown = function (e ){
Coordinate (e );
Pd = true;
Mx = mouseX;
My = mouseY;
Ctx. save ();
}
CanvasDom. onmousemove = function (e ){
DrawLine (e );
}
CanvasDom. onmouseup = function (e ){
Pd = false;
}
This. drawLine = function (e ){
Coordinate (e );
If (pd = true ){
Ctx. save ();
Ctx. beginPath ();
Ctx. moveTo (mx, my );
Ctx. lineTo (mouseX, mouseY );
Ctx. closePath ();
Ctx. stroke ();
Mx = mouseX;
My = mouseY;
}
}
This. setLineWidth = function (lw) {ctx. lineWidth = lw ;}
This. chooseColor = function (c) {ctx. strokeStyle = c ;}

<! -- Html -->

<Canvas id = "myCanvas" width = "400" height = "400" style = "border: solid 1px #000;"> </canvas> <br>
<Input type = "button" value = "Draw line" id = "button_line">
<Input type = "text" ...... remaining full text>

Related Article

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.