The first html5 knife in IE9-html5 tutorial skills-

Source: Internet
Author: User
I will not try the technology that Microsoft does not support. I will try it when Microsoft says it wants to support it. Maybe it's just a habit to follow Microsoft's path, but it's silly to think about it. Mvc is a good thing. Why don't you learn it when you get started? You have to wait until asp.net mvc comes out. orm is a good thing, why do I have to wait until EF comes out to learn it? html5 is a good thing. Why do I have to wait until IE9 comes out to learn it ?......

-- I think I should get rid of this bad problem.

No more nonsense.

Requirement: The coords value in html code is generated by imitating the function of adding an anchor to an image in dreamweaver.

Technical analysis: intuition tells me that html5 canvas is competent.

Since I have never had any substantive experience with canvas, I only read the demo developed by others using canvas, so I had to bing the html5 canvas tutorial. The following link was found: http://kb.operachina.com/node/190

Write code after reading the document:

Code Analysis:

1.1 html: use an image as the base, and place the canvas on it for drawing.

1.2 css

1.3 javascript: cursor: mousedown, mousemove, and mouseup


The Code is as follows:





Some info to tell the people whose broswer doesn't support html5





Experienced users may know that this html5 code is doomed to be a tragedy. When there is an img element under the canvas, the canvas is not transparent in any case, if you forget the canvas, you may not be able to draw things. It seems that this canvas element is "clean" and does not want to be in the same flow with other low-level elements. Even if I want to leave, the background elements of cantainer cannot appear. I think this canvas may not be transparent to other elements. So the above Code is actually the wrong code...

So how can we achieve the effect of layers similar to those in photoshop? That is, get a few more canvas elements, replace the above img with a canvas, and then draw the img onto the canvas, so that the canvas is transparent to the canvas. The Code is as follows:

The Code is as follows:





Some info to tell the people whose broswer doesn't support html5





The html is done, and the next step is to draw on the canvas. With javascript, this task is very simple.


The Code is as follows:


Window. addEventListener ('load', function (){
// Get the canvas element.
Var elem = document. getElementById ('bg ');
If (! Elem |! Elem. getContext ){
Return;
}
// Get the canvas 2d context.
Var context = elem. getContext ('2d ');
If (! Context |! Context. drawImage ){
Return;
}
// Create a new image.
Var img = new Image ();
// Once it's loaded draw the image on the canvas.
Img. addEventListener ('load', function (){
// Original resolution: x, y.
Context. drawImage (this, 0, 0 );
// Now resize the image: x, y, w, h.
Context. drawImage (this, 160, 0,120, 70 );
// Crop and resize the image: sx, sy, sw, sh, dx, dy, dw, dh.
Context. drawImage (this, 8, 20,140, 50, 0,150,350, 70 );
}, False );
Img. src = 'HTTP: // www.sh1800.net/navpic/20100917.jpg ';
}, False );
// The Code obtained directly in the Document. Note that it is required for the opera and ie9 onload events. Otherwise, the image will be blank. Of course, this will not happen in Chrome.


To be continued ....
Original address http://www.cnblogs.com/ice6/archive/2010/09/18/1830020.html

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.