Typical JavaScript code (9)

Source: Internet
Author: User

<Style>
Body {
Font-size: 9pt;
}
TD {
Font-size: 9pt; line-Height: 11pt;
}
Input {
Font-size: 9pt;
}
Select {
Font-size: 9pt; text-align: center; width: 100px;
}
SPAN {
Font-size: 12pt;
}
</Style>

<Script language = JavaScript>
/*
All files are designed & writen by windy_sk, you can use it freely...
You must keep this item!
Email: <a href = "mailto: windy_sk@126.com"> windy_sk@126.com </a>
*/

Window. onload = function (){
VaR color_list = new array ();
VaR hex = new array (6 );
VaR curcolor;
VaR curindex;
Hex [0] = "FF"
Hex [1] = "cc"
Hex [2] = "99"
Hex [3] = "66"
Hex [4] = "33"
Hex [5] = "00"
For (VAR x = 0; x <6; X ++ ){
For (var y = 0; y <6; y ++ ){
For (VAR z = 0; Z <6; Z ++ ){
Curcolor = hex [x] + hex [y] + hex [Z];
Curindex = color_start.options.length;
Color_start.options [curindex] = New Option ("", curcolor );
Color_start.options [curindex]. style. backgroundcolor = "#" + curcolor;
Curindex = color_end.options.length;
Color_end.options [curindex] = New Option ("", curcolor );
Color_end.options [curindex]. style. backgroundcolor = curcolor;
}
}
}
}

Function dec2any (STR, num ){
If (! /\ D +/. Test (STR) return Nan;
If (! /\ D +/. Test (Num) return Nan;
VaR num = eval (Num );
If (Num> 36 | num <2) return Nan;
VaR the_str = "0123456789 abcdefghijklmnopqrstuvwxyz ";
VaR STR = eval (STR );
VaR residue = 0;
VaR result = "";
While (true ){
Residue = STR % num;
Result = the_str.charat (residue) + result;
If (STR <num) break;
STR = math. Floor (Str/num );
}
Return (result );
}

Function get_color (the_num ){
If (the_num> 255) the_num = 255;
If (the_num <0) the_num = 0;
VaR the_color = dec2any (the_num, 16 );
If (the_color.length = 1) the_color = "0" + the_color;
Return the_color;
}

Function build_text (STR, c_start, c_end ){
VaR the_len = Str. length;
VaR r_start = eval ("0x" + c_start.substr (0, 2 ));
VaR r_end = eval ("0x" + c_end.substr (0, 2 ));
VaR r_unit = math. Floor (r_start-r_end)/the_len );
VaR g_start = eval ("0x" + c_start.substr (2, 2 ));
VaR g_end = eval ("0x" + c_end.substr (2, 2 ));
VaR g_unit = math. Floor (g_start-g_end)/the_len );
VaR B _start = eval ("0x" + c_start.substr (4, 2 ));
VaR B _end = eval ("0x" + c_end.substr (4, 2 ));
VaR B _unit = math. Floor (B _start-B _end)/the_len );
VaR curcolorstr = "";
VaR resultstr = "";
VaR TMP;
Show. value = "";
For (VAR I = 0; I <the_len; I ++ ){
Curcolorstr = "#";
Curcolorstr + = get_color (r_start-I * r_unit );
Curcolorstr + = get_color (g_start-I * g_unit );
Curcolorstr + = get_color (B _start-I * B _unit );
Resultstr + = "<font color = '" + curcolorstr + "'>" + Str. substr (I, 1) + "</font> ";
Show. Value + = "<font color = '" + curcolorstr + "'>" + Str. substr (I, 1) + "</font> \ n ";
}
Return resultstr;
}

Function buildit (){
Clearinterval (flash_timer );
Showtext. innerhtml = build_text (the_text.value, color_start.value, color_end.value );
If (flash. Checked) flash_text ();
}

VaR flash_timer = NULL;
VaR color_list = NULL;

Function flash_text (){
VaR obj_list = showtext. Children;
Color_list = new array ();
For (VAR I = 0; I <obj_list.length; I ++ ){
Color_list [color_list.length] = showtext. Children [I]. color;
}
Flash_timer = setinterval ("flashit ()", 50 );
}

Function flashit (){
VaR tmp_arr = new array ();
For (VAR I = 0; I <color_list.length-1; I ++ ){
Tmp_arr [I + 1] = color_list [I];
}
Tmp_arr [0] = color_list [I];
Color_list = tmp_arr;
For (VAR I = 0; I <color_list.length; I ++ ){
Showtext. Children [I]. Color = color_list [I];
}
}

</SCRIPT>

<Table>
<Tr>
<TD colspan = 3> display text: <input id = the_text type = text size = 50 value = "Rainbow text rainbow text"> </TD>
</Tr>
<Tr>
<TD> start color: <select id = "color_start" onchange = "buildit (); the_text.focus ()"> </SELECT> </TD>
<TD> ---- </TD>
<TD> end color: <select id = "color_end" onchange = "buildit (); the_text.focus ()"> </SELECT> </TD>
</Tr>
<Tr>
<TD colspan = 3> <input id = flash type = checkbox onclick = "This. checked? Flash_text (): clearinterval (flash_timer) "> <label for = flash> blinking </label> </TD>
</Tr>
</Table>
<Span id = showtext style = ""> </span>
<Br>
<Textarea id = show rows = 15 Cols = 50> </textarea>

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.