Asp.net JavaScript sliding and shrinking multi-level menu

Source: Internet
Author: User

Let's take a look at the final effect: http://www.orfeo-Casa/index. aspx left menu

Major javascript:

<SCRIPT type = "text/JavaScript">

// <! [CDATA [
Window. onload = function (){
Rolintab ("Rolin ")
}
Function rolintab (OBJ ){
VaR list = $ (OBJ). getelementsbytagname ("Li ");
VaR state = {Show: false, hidden: false, showobj: false };

For (VAR I = 0; I <list. length; I ++ ){
VaR TMP = new rolinitem (list [I], State );
If (I = 0) TMP. pshow ();
}
}

Function rolinitem (OBJ, state ){
VaR speed = 0.0666;
VaR range = 1;
VaR interval;
VaR tarh;
VaR tar = this;
VaR head = getfirstchild (OBJ );
VaR content = getnextchild (head );
VaR isopen = false;
This. phidden = function (){
If (isopen) Hidden ();
}
This. pshow = show;

VaR baseh = content. offsetheight;
Content. style. Display = "NONE ";
VaR isopen = false;

Head. onmouseover = function (){
This. style. Background = "#000 ";
}

Head. onmouseout = mouseout;

Head. onclick = function (){
This. style. Background = "#000 ";
If (! State. Show &&! State. Hidden ){
If (! Isopen ){
Head. onmouseout = NULL;
Show ();
} Else {
Hidden ();
}

}
}

Function mouseout (){
This. style. Background = "#000"
}
Function show (){
Head. style. borderbottom = "1px solid # dadada ";
State. Show = true;
If (State. openobj & State. openobj! = TAR ){
State. openobj. phidden ();
}
Content. style. Height = "0px ";
Content. style. Display = "Block ";
Content. style. Overflow = "hidden ";
State. openobj = tar;
Tarh = baseh;

Interval = setinterval (move, 10 );
}
Function shows (){
Isopen = true;
State. Show = false;
}

Function hidden (){
State. Hidden = true;
Tarh = 0;
Interval = setinterval (move, 10 );
}

Function hiddens (){
Head. style. borderbottom = "NONE ";
Head. onmouseout = mouseout;
Head. onmouseout ();
Content. style. Display = "NONE ";
Isopen = false;
State. Hidden = false;
}

Function move (){
VaR Dist = (tarh-content. style. Height. pxtonum () * speed;
If (math. Abs (DIST) <1) Dist = DIST> 0? 1:-1;
Content. style. Height = (content. style. Height. pxtonum () + dist) + "PX ";
If (math. Abs (content. style. Height. pxtonum ()-tarh) <= range ){
Clearinterval (interval );
Content. style. Height = tarh + "PX ";
If (tarh! = 0 ){
Shows ()
} Else {
Hiddens ();
}
}
}

}
VaR $ = function ($) {return document. getelementbyid ($ )};
String. Prototype. pxtonum = function () {return number (this. Replace ("PX ",""))}
Function getfirstchild (OBJ ){
VaR result = obj. firstchild;
While (! Result. tagname ){
Result = result. nextsibling;
}
Return result;
}
Function getnextchild (OBJ ){
VaR result = obj. nextsibling;
While (! Result. tagname ){
Result = result. nextsibling;
}
Return result;
}
//]>

</SCRIPT>

Step 2: Let me introduce in detail how to dynamically generate a menu:

HTML section:

<Div id = "Left">
<Asp: literal id = "ltacategory" runat = "server"> </ASP: literal>
</Div>

Code:

Protected void page_load (Object sender, eventargs E)
{
If (! Page. ispostback)
{
This. ltacategory. Text = getcategory ();
}
}

/// <Summary>
/// Obtain the product category
/// </Summary>
/// <Returns> </returns>
Public String getcategory ()
{
Maticsoft. BLL. productclass BLL = new maticsoft. BLL. productclass ();
List <maticsoft. model. productclass> List = maticsoft. BLL. productclass. get_list ();
Stringbuilder strresult = new stringbuilder ();
Strresult. appendline ("<ul class = \" rolinlist \ "id = \" Rolin \ "> ");
If (list. Count> 0)
{
Foreach (maticsoft. model. productclass model in List)
{
Strresult. appendline ("<li> ");
Strresult. append (string. Format ("<H2 >{0} </H2>", model. productname ));
Strresult. appendline ("<Div class = \" content \ "> ");
Strresult. appendline (getchildcategory (model. Id. tostring ()));
Strresult. appendline ("</div> ");
}
}
Strresult. appendline ("</ul> ");
Return strresult. tostring ();
}
String getchildcategory (string parentid)
{
List <maticsoft. model. productclass> List = maticsoft. BLL. productclass. get_list (parentid );
Stringbuilder strresult = new stringbuilder ();
If (list. Count> 0)
{
Foreach (maticsoft. model. productclass model in List)
{
Strresult. appendline (string. Format ("<a href = \"/list. aspx? Cid = {0} & Action = bind \ "> {1} </a> <br/>", model. ID, model. productname ));
}
}
Return strresult. tostring ();
}

 

 

 

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.