Drop-down menu in Javascript design webpage

Source: Internet
Author: User
In order to better organize information and clearly classify and arrange displayed information, web page makers often have to worry about it. Common methods use tree structures to display information, use tables for webpage layout, and use frames to organize pages. In order to better organize information and clearly classify and arrange displayed information, web page makers often have to worry about it. Common methods use tree structures to display information, use tables for webpage layout, and use frames to organize pages. However, for users who are used to Windows operating systems, menu operations can be the most natural method. Next, let's take a look at how to design drop-down menus on the webpage. The drop-down menu consists of several main menu items displayed at the top of the window and sub-Menus under each menu bar. Each sub-menu usually contains several sub-menu items. Generally, the sub-menu of a menu bar is displayed only when the mouse pointer points to the menu bar. When the mouse pointer leaves the menu, the sub-menu is hidden and returns to the status where only the main menu bar is displayed.

Based on the above drop-down menu features, we can start to create a drop-down menu in the web page. We place an area on the top of the page to display the main menu bar, each of which is placed as a hyperlink horizontally in this area, unless the menu item does not have a sub menu, generally, the hyperlink here does not point to any address. It is used only to activate the submenu. For the format of the Region, see program 1.

  

  
DoMenu ('idpad1'); "onclick =" window. event. returnValue = false; "> menu item 1

  
DoMenu ('idpad2'); "onclick =" window. event. returnValue = false; "> menu item 2

......

     

Next, we define the corresponding sub-menus based on the number of main menu items and define an area for each sub-menu. The first element in this area is a horizontal line, then, each sub-menu is placed in this area as a hyperlink. Due to the vertical arrangement of sub-menus
Line feed. Of course, this area cannot be displayed yet, but when it is activated, its display position should be on top of other objects, so its style attribute is set to STYLE = 'display: none; z-index: 9 ;'. Note that the ID of each hyperlink should be the same as the ID of the main menu for unified processing. For the format, see Program 2.

  

  

  

  

Sub-menu items


  

Sub-menu item one or two


  

  

Sub-menu item 1 and 3


......

  

     

After the above steps, the drop-down menu format has been defined, and the following task is to control the display and hide of these sub-menus.

When you move the cursor over the main menu bar, its sub-menus should be displayed. We will execute doMenu (MenuID) to respond to the onmouseover event of the main menu. The MenuID of the process parameter represents the ID of the sub-menu area. During execution, set window. event. cancelBubble = true and calculate the position displayed in the sub-menu, including the coordinates in the upper left and lower right corner. Run the following statement to display the region of the sub-menu:

CurMenu. style. clip = "rect (0 0 0 0)"; CurMenu. style. display = "block ";

When you move the cursor out of the main menu, you can move the cursor between the sub-menu and its main menu. In this case, the sub-menu cannot be hidden; in another case, you need to hide the sub-menu when you move the mouse out of the sub-menu and its main menu area. We can execute hideMenu () to respond to onmouseout of the main menu, and execute hideMenu () to respond to onmouseout events in the region where the sub-menu is located.

The functions of the two functions mouseout () and mouseover () on the webpage are very simple. They are used to handle the color changes of menu items when the mouse moves.

For the complete source code, see www.pccomputing.com.cn.

The Webpage Browsing result 1 shows that the running environment is IE4.0 or later.

(Figure note WANGYE)

  

  

   Drop-down menu in the webpage

  

  
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.