How to use JavaScript and CSS to generate a dropdown menu

Source: Internet
Author: User

There are a lot of source code about JS menus, and there are also a lot of pure CSS. They are encapsulated well, but it is not easy to modify because the internal logic is complicated. The disadvantage of the CSS dropdown menu is that the browser is too compatible with too many codes, which may cause poor readability.

The principle is actually very simple:
1. Use an absolute Div, show during onmouseover, and hide during onmouseout.
2. Use the location of the relative parent Div, and the position of the DIV is relative to the parent element;
3. For mouseout messages, because the parent node is the unit, the sub-node can use table to solve the problem of mouse movement.

 

Function displaymenu (ID, visible)
...{
VaR OBJ = Document. getelementbyid (ID );
If (OBJ = NULL)
...{
Alert (ID + "-- not found! ");
Return;
}
If (visible)
OBJ. style. Visibility = 'visable'
Else
OBJ. style. Visibility = 'den den'
}

<Ul> <li> <a href = ""> Chongqing </a> </LI> <li> <a href = ""> Hangzhou </a> </Li> <li> <a href = ""> Nanjing </a> </LI> <li> <a href = ""> Shanghai </a> </LI> <li class = "citymenu" onmouseover = "displaymenu ('morecity ', true); "onmouseout =" displaymenu ('morecity ', false ); "> More> <Table id =" morecity "> <tr> <TD> <a href =" "> Chengdu </a> </TD> <a href = ""> Zhengzhou </a> </TD> </tr> </table> </LI> </ul>

Or directly go to my home page to capture code, see the effect, huh, http://www.yofun.cn

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.