Learn HTML5 13 HTML5 color selector from kingdz

Source: Internet
Author: User

This lesson shows you two examples. Of course, they are very simple.

The first effect is the color selector. The effect is as follows:

I think many people have done this in other versions. By the way, this is a simple implementation in HTML5.

The first thing to do is to prepare for the job.

   <  Canvas  ID  = "Text"  Width  = "100"  Height  = "100"> </  Canvas  > <  P  > Red: <  Input Type  = "Range"  ID  = "Red"  Min  = "0"  Max  = "255"  Value  = "0"  Onchange  = "Fill ();"/> </  P  > <  P  > Green: <  Input Type  = "Range"  ID  = "Green"  Min  = "0"  Max  = "255"  Value  = "0"  Onchange  = "Fill ();"/> </  P  > <  P  > Blue: <  Input Type  = "Range"  ID  = "Blue"  Min  = "0"  Max  = "255"  Value  = "0"  Onchange  = "Fill ();"/> </  P  > Current color: <  Span  ID  = "Showcolor"> </ Span  > 

This time we use the range slider to achieve the desired effect.

 <  Script  Type  = "Text/JavaScript"> VaR C = Document. getelementbyid ( "Text" ); VaR CTX = C. getcontext ( "2D" ); VaR Red = Document. getelementbyid ( "Red" ); VaR Green = Document. getelementbyid ("Green" ); VaR Blue = Document. getelementbyid ( "Blue" ); Function Fill () {CTX. fillstyle = "RGB (" + Red. Value + "," + Green. Value + "," + Blue. Value + ")" ; Document. getelementbyid ( "Showcolor" ). Innerhtml = CTX. fillstyle; CTX. fillrect (0, 0,100,100 );} </  Script > 

SeeCode? Haha, it's very simple. You can see it at a Glance. (* ^__ ^ *) Hey ......

The second example is the color belt effect, which is a random color display effect. Well, you should pay attention to these things that may be used in the future.

  <  Canvas  ID  = "Text"  Width  = "400"  Height  = "400"> This label is not supported </  Canvas  > <  Input  Type = "Button"  Value  = "Start running"  Onclick  = "Setinterval (move, 1);"/> <  Script  Type  = "Text/JavaScript"> VaR C = Document. getelementbyid ( "Text" ); VaR CTX = C. getcontext ( "2D" ); VaR Width = parseint (C. getattribute ( "Width" ));VaR Height = parseint (C. getattribute ( "Height" )); VaR Imagedata = CTX. createimagedata (width, height ); Function Move (){ VaR X = 200; For ( VaR Y = 0; y  "RGB (" + Parseint (math. Random () * 256) + "," + Parseint (math. Random () * 256) + "," + Parseint (math. Random () * 256) +")" ); CTX. fillrect (X, Y, 50, 50 );};} </  Script  > 

These two examples are not very difficult. They mainly involve a small test of your familiarity. I will give you some interesting results in future courses. Today's simple course is over.

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.