Home >Web Front-end >JS Tutorial >A drop-down menu combining css and js supports mainstream browsers_javascript skills
First statement:
Although I have worked in a web front-end position for many years, the technical requirements of the position are not high. HTML and CSS are mostly used, but JavaScript is rarely original and is basically copied and modified. Therefore, when I actually write it, I find that the foundation is not solid. I learn and practice at the same time, and I gain a lot.
Rendering:
No more nonsense, let’s post the code
1. css code
2. JavaScript code
3. html code
Description:
1. Considering that ul and li pages are commonly used, you can add #menu1 before css to limit the scope of the menu style.
2. The js mainly listens for the mouse move in and removal events, and switches to the limouseover and limouseout styles accordingly; at the same time, it changes the display attribute of the submenu to achieve the display and hide function.
3. The same page can be called repeatedly without conflict. The JavaScript code in the html code is the calling instance. The previous menu1 is an arbitrary variable name, and the menu1 in the brackets is the id in the html page.
Disadvantages of this example:
1. The styles of mouseover and mouseout of menu li and submenu li are the same, that is, the same color and font, and no separate settings are implemented.
2. Since it needs to be compatible with Ie6 and ie7, while position:absolute is used, the left and top attributes are added. The top should be set according to the overall height of the menu li.