This article shares the specific code for JavaScript to display and hide the drop-down menu for your reference. The specific content is as follows Sometimes this page effect is needed: When the mouse moves over an element, a drop-down menu is implemented. When the mouse moves away from the element, the drop-down menu disappears. Implementation ideas 1. A box contains two parts, the lower part is the submenu, which is set to be hidden first: display: none; Code Sample<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Operation element-Sina drop-down menu</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } ul li { list-style: none; } a { text-decoration: none; color: #4c4c4c; } a:hover { color: #e88415; } .box { width: 80px; margin: 50px auto; font-size: 14px; color: #4c4c4c; } .weibo { position: relative; background-color: #fcfcfc; } .weibo a { display: block; height: 40px; line-height: 40px; padding-left: 20px; } .change { color: #f9a74f; background-color: #edeef0; } i { position: absolute; top: 50%; right: 15px; margin-top: -4px; width: 5px; height: 5px; border-bottom: 1px solid orangered; border-right: 1px solid orangered; transform: rotate(45deg); } .weiboList { display: none; } .weiboList li a { display: block; width: 80px; height: 33px; line-height: 33px; padding-left: 15px; border-bottom: 1px solid #fecc5b; background-color: #fff; } .weiboList li a:hover { background-color: #fff5da; } </style> </head> <body> <div class="box"> <div class="weibo"><a href="#" >Weibo<i class="select"></i></a></div> <ul class="weiboList"> <li><a href="#" >Private Message</a></li> <li><a href="#" >Comments</a></li> <li><a href="#" >@Me</a></li> </ul> </div> <script> var box = document.querySelector('.box'); var weibo = document.querySelector('.weibo'); var weiboList = document.querySelector('.weiboList'); box.onmouseover = function() { weibo.className = 'weibo change' weiboList.style.display = 'block'; } box.onmouseout = function() { weibo.className = 'weibo'; weiboList.style.display = 'none'; } </script> </body> </html> Page effect: The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: VMware virtual machine installation Apple Mac OS super detailed tutorial
How to view version information under Linux, incl...
1. Function: xargs can convert the data separated...
Table of contents Preface: accomplish: Summarize:...
Anti-shake: Prevent repeated clicks from triggeri...
Table of contents 1. Parameters that determine ca...
(1) Server configuration: [root@localhost ~]# cd ...
Introduction EXISTS is used to check whether a su...
Copy code The code is as follows: <style type=...
Sometimes it is necessary to perform simple verif...
In the MySQL database, after tables are associate...
There are many XHTML tags: div, ul, li, dl, dt, d...
docker-compose.yml version: '2' services:...
This also caused the inability to upload png files...
Not only does it reduce the cost of website develo...
The parent node of the parent node, for example, t...