Typical JavaScript code (6)

Source: Internet
Author: User

<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>
*/

VaR Ie = (document. getelementbyid & document. All );
VaR NS = (document. getelementbyid &&! Document. All );
VaR load_end = false;

Function menuitem (name ){
This. menu_name = Name;
This. item_list = new array ();
This. Add = function (title, link ){
This. item_list.push ([title, LINK]);
}
}

VaR menu_list = new array ();
VaR n = 0;
Menu_list [N] = new menuitem ("test1 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("444 ","#");
Menu_list [N]. Add ("555 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
N ++;
Menu_list [N] = new menuitem ("Test2 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
N ++;
Menu_list [N] = new menuitem ("test3 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("333 ","#");
N ++;
Menu_list [N] = new menuitem ("test4 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("333 ","#");
N ++;
Menu_list [N] = new menuitem ("test5 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
N ++;
Menu_list [N] = new menuitem ("test6 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
N ++;
Menu_list [N] = new menuitem ("test7 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("444 ","#");
Menu_list [N]. Add ("555 ","#");
Menu_list [N]. Add ("666 ","#");
Menu_list [N]. Add ("777 ","#");
N ++;
Menu_list [N] = new menuitem ("test8 ");
Menu_list [N]. Add ("111 ","#");
Menu_list [N]. Add ("222 ","#");
Menu_list [N]. Add ("333 ","#");
Menu_list [N]. Add ("444 ","#");
Menu_list [N]. Add ("555 ","#");
Menu_list [N]. Add ("666 ","#");
Menu_list [N]. Add ("777 ","#");
Menu_list [N]. Add ("888 ","#");
Menu_list [N]. Add ("999 ","#");
N ++;

VaR css_menu = "padding: 0px; color: #000000; position: absolute; Borde: 0px; overflow-Y: visible; display: none; zindex: 999; filter: alpha (opacity = 100 );";
VaR css_menu_tbl = "padding: 0px; width: 100%; Background-color: # eeeeee; Border: 1px #999999 dotted; border-collapse: collapse ;";
VaR css_menu_itm = "padding: 5px; cursor: pointer ;";
VaR css_menu_list = "padding: 0px; width: 100%; border-collapse: collapse; Background-color: black; Border: #999999 1px solid ;";

Menu = Document. createelement ("Div ");
Menu. innerhtml = "";
Menu.style.css text = css_menu;

Function build_menu_list (){
VaR content = "";
Content + = "<Table border = '1' cellpadding = '2' style = '" + css_menu_list + "'> <tr bgcolor = '# ffcc00'> \ n ";
For (VAR I = 0; I <menu_list.length; I ++ ){
Content + = "<TD style = 'cursor: pointer; padding: 2px 'onmouseover = \" showmenu (event, "+ I + ") \ ">" + menu_list [I]. menu_name + "</TD> \ n ";
}
Content + = "</tr> </table> \ n ";
Document. writeln (content );
}

VaR step = 5;
VaR step_alpha = math. Ceil (100/step );
VaR step_heigh = 0;

Function showmenu (E, n ){
If (! Load_end) return;
VaR OBJ = ie? E. srcelement: e.tar get;
If (obj. tagname. tolowercase ()! = "TD") return;
Menu. innerhtml = "";
Menu. style. Display = "NONE ";
Menu. style. overflowy = "visible ";
Menu. style. Height = "0px ";
If (IE) menu. Filters. Alpha. Opacity = 0;
If (NS) menu. style. Condition opacity = "0%"
 
VaR Pos = new get_pos (OBJ );
VaR content = "";
Content + = "<Table border = '1' style = '" + css_menu_tbl + "'> ";
For (I = 0; I <menu_list [N]. item_list.length; I ++ ){
Content + = "<tr> <TD style = '" + css_menu_itm + "'onmouseover = \" this. bgcolor = '# bec5de' \ "onmouseout = \" this. bgcolor = ''\"> <a href = '"+ menu_list [N]. item_list [I] [1] + "'>" + menu_list [N]. item_list [I] [0] + "</a> </TD> </tr> ";
}
Content + = "</table> ";
Step = I;
Menu. innerhtml = content;
With (menu. Style ){
Left = POS ["Left"];
Top = POS ["TOP"] + parseint (obj. offsetheight );
Width = obj. offsetwidth;
Display = "";
Step_alpha = math. Ceil (60/step );
Step_heigh = menu. offsetheight/step;
Borderbottom = "1px #999999 dotted ";
Height = "1px ";
Overflowy = "hidden ";
}
Fadeout_menu ();
Return;
}

VaR timer = NULL;
Function fadeout_menu (){
Cleartimeout (timer );
VaR cur_level = parseint (ie? Menu. Filters. Alpha. opacity: menu. style. Hierarchical opacity );
Cur_level + = step_alpha;
If (cur_level> 60) cur_level = 60;
If (IE) menu. Filters. Alpha. Opacity = cur_level;
If (NS) menu. style. Condition opacity = cur_level + "% ";
Menu. style. Height = parseint (menu. style. Height) + step_heigh;
If (cur_level! = 60 ){
Timer = setTimeout ("fadeout_menu ()", 150 );
} Else {
Menu. style. borderbottom = "";
}
}

Function get_pos (the_obj ){
The_top = the_obj.offsettop;
The_left = the_obj.offsetleft;
While (the_obj = the_obj.offsetparent ){
The_top + = the_obj.offsettop;
The_left + = the_obj.offsetleft;
}
This. Top = the_top;
This. Left = the_left;
}

Window. onload = function (){
Load_end = true;
Document. Body. appendchild (menu );
}

Document. onclick = function (){
Menu. style. Display = "NONE ";
}

Build_menu_list ();
</SCRIPT>
<Body bgcolor = "# ffffee"> </body>

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.