Extjs: The menu is automatically hidden after the mouse is removed from the menu.

Source: Internet
Author: User

Extjs: The menu is automatically hidden after the mouse is removed from the menu.

1. extjs2.0.2 is used.

2. The problems encountered are briefly described as follows:

When the drop-down menu is displayed, if you move the mouse away without any operation, the menu will not disappear (hide) automatically and will always be displayed on the screen.

You must click a menu item or click somewhere else on the page to hide the menu ).

3. In order to enhance the user experience, after removing the mouse from the drop-down menu, the menu can be automatically hidden.

Below is the test demoCode:

 
<% @ Page Language = "Java" pageencoding = "UTF-8" %>

<HTML>
<Head>
<Title> test </title>
<LINK rel = "stylesheet" type = "text/CSS" href = "./extjs/ext-all.css"/>
<LINK rel = "stylesheet" type = "text/CSS" href = "./extjs/ext-patch.css"/>
<SCRIPT type = "text/JavaScript" src = "../extjs/ext-base.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../extjs/ext-all.js"> </SCRIPT>
<SCRIPT type = "text/JavaScript" src = "../extjs/ext-lang-zh_CN.js"> </SCRIPT>

<SCRIPT type = text/JavaScript>

Ext. onready (function (){
Ext. quicktips. INIT ();

// Sub-menu items
VaR menu1_1_1 = new Ext. Menu. menu ({
ID: 'menu1 _ 1_1 ',
Items :[
{ID: "1551", text: 'test 1', Handler: onitemclick },
{ID: "1552", text: 'test 2', Handler: onitemclick },
{ID: "1553", text: 'test 3', Handler: onitemclick}
]
});
// Sub-menu items
VaR menu1_1 = new Ext. Menu. menu ({
ID: 'menu1 _ 1 ',
Items :[
{ID: "151", text: 'subitem 1', Handler: onitemclick },
{ID: "152", text: 'subitem 2', Handler: onitemclick },
{ID: "153", text: 'subitem 3', Handler: onitemclick },
{ID: "154", text: 'subitem 4', Handler: onitemclick },
{ID: "155", text: 'subitem 5', menu: menu1_1_1}]
});
// Menu 1
VaR menu1 = new Ext. Menu. menu ({
ID: 'menu1 ',
Items :[
{ID: "11", text: 'menu item 1', Handler: onitemclick },
{ID: "12", text: 'menu item 2', Handler: onitemclick },
{ID: "13", text: "menu item 3", Handler: onitemclick },
{ID: "14", text: "menu item 4", Handler: onitemclick },
{ID: "15", text: "menu item 5", menu: menu1_1 },
{ID: "16", text: "menu item 6", Handler: onitemclick}
]
});

// Menu 2
VaR menu2 = new Ext. Menu. menu ({
ID: 'menu2 ',
Items :[
{ID: "21", text: 'menu 1', Handler: onitemclick },
{ID: "22", text: "menu 2", Handler: onitemclick },
{ID: "23", text: "menu 3", Handler: onitemclick}
]
});

// Menu 3
VaR menu3 = new Ext. Menu. menu ({
ID: 'menu3 ',
Items :[
{ID: "31", text: 'menu 4', Handler: onitemclick },
{ID: "32", text: "menu 6", Handler: onitemclick}
]
});

VaR d_menu1 = ext. Get ("d_menu1 ");
VaR d_menu2 = ext. Get ("d_menu2 ");
VaR d_menu3 = ext. Get ("d_menu3 ");

D_menu1.on ("Mouseover ",
Function (e ){
Menu1.show (d_menu1 );}
);

D_menu2.on ("Mouseover ",
Function (e ){
Menu2.show (d_menu2 );}
);

D_menu3.on ("Mouseover ",
Function (e ){
Menu3.show (d_menu3 );}
);

// After the mouse moves out of the menu, the menu is automatically hidden.
VaR mouseouthidemenu = function (mymenu ){
Mymenu. On ("mouseout ",
Function (menu, E, itme ){
If (! E. getrelatedtarget (). Contains (E. gettarget ())&&! Menu. getel (). Contains (E. getrelatedtarget ())){

// The following if statement determines whether the mouse is moved to the sub-menu.
If (! Ext. Get (E. gettarget (). hasclass ('x-menu-item ')){
Hideallmenu ();
}
} Else
If (E. getrelatedtarget (). Contains (menu. getel (). DOM )){
// The following if statement determines whether the mouse is moved to the sub-menu.
If (! Ext. Get (E. gettarget (). hasclass ('x-menu-item-Icon ')&&! Ext. Get (E. gettarget (). hasclass ('x-menu-item ')){
Hideallmenu ();
}
}
});
}

// Add listeners for each menu item
Mouseouthidemenu (menu1 );
Mouseouthidemenu (menu2 );
Mouseouthidemenu (menu3 );
Mouseouthidemenu (menu1_1 );
Mouseouthidemenu (menu1_1_1 );

VaR hideallmenu = function (){
// Hide the menu
Menu1.hide ();
Menu2.hide ();
Menu3.hide ();
Menu00001.hide ();
Menu1_1_1.hide ();
}

VaR page_header = ext. Get ('menu _ head ');

Page_header.on ("Mouseover", function (e ){
Hideallmenu (); // hide a menu
});
});

Function onitemclick (item ){
// Alert ('click! ');
}
</SCRIPT>
</Head>

<Body>

<Div id = "menu_header">
<Table Height = "20" cellspacing = "0" cellpadding = "0" width = "1004" border = "0">
<Tr>
<TD> welcome </TD>
</Tr>
</Table>
</Div>

<Table Height = "50" width = "1004" border = "0" cellpadding = "0" cellspacing = "0">
<Tr>
<TD> <Div id = "d_menu1"> menu 1 </div> </TD>
<TD> <Div id = "d_menu2"> menu 2 </div> </TD>
<TD> <Div id = "d_menu3"> menu 3 </div> </TD>
<TD>
</Tr>
</Table>

</Body>
</Html>

 

[-End-]

By jrq

2010/12/30

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.