Use Javascript to implement a drop-down menu for your reference. The specific contents are as follows I am still learning the big front end. Please forgive me if there are any irregularities or incorrect ideas in the code. Thank you for your advice. Drop-down menus or side menus are very practical in actual development Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <style> *{ padding: 0; margin: 0; border: 0; } .menu{ width: 100%; height: 50px; border: 1px solid lightyellow; box-shadow: 0 2px 5px black; } .menu div{ /*margin-top: 10px;*/ float: left; width: 19.82%; height: 50px; /* border: 1px solid red;*/ text-align: center; } button{ margin-top: 15px; cursor: pointer; width: 25px; height: 15px; background-color: pink; } .show1{ display: none; width: 19.82%; height: 250px; /*border: 1px solid black;*/ } .show1 div{ border: 1px solid pink; width: 247px; height: 48px; text-align: center; } a{ text-decoration: none; display: block; margin-top: 10px; } a:hover{ color: #ff242d; font-size: 25px; } </style> </head> <body> <div class="menu"> <div> drop down 1 <button>^</button> </div> <div> drop-down 2 <button>^</button> </div> <div> drop down 3 <button>^</button> </div> <div> drop down 4 <button>^</button> </div> <div> drop down 5 <button>^</button> </div> </div> <div class="show1"> <div><a href="#" >4654tyyut</a></div> <div><a href="#" >4654</a></div> <div><a href="#" >sdf</a></div> <div><a href="#" >sdf</a></div> <div><a href="#" >tert</a></div> </div> <script> var btn = document.querySelector('button') var show1 = document.querySelector('.show1') var flag=0 btn.onclick = function () { if (flag === 0) { show1.style.display = 'block' flag=1 }else { show1.style.display='none' flag=0 } } </script> </body> </html> Code Explanation Here we mainly use the onclick of the script to implement it. The button I use here can also be replaced with other things, and the methods are similar. After clicking the corresponding thing onclick, an event will be triggered, the function will be called, and then the value of the flag will be judged to perform corresponding operations, hiding/displaying the div. The flag here is the key. This variable keeps changing between 0.1 when a click event occurs. The function is executed once when the click occurs, that is, the loop is executed once, that is, the value of the flag is judged, so as to achieve the effect of displaying/hiding. Demonstration effect When not pulled down After pulling down 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:
|
<<: Using Docker run options to override settings in the Dockerfile
>>: Mysql GTID Mha configuration method
Preface The source code is only more than 100 lin...
Install axios and implement communication Here we...
1. Modify the Linux server docker configuration f...
Table of contents 1. Comparison of data before an...
About who Displays users logged into the system. ...
Table of contents Preparation Install VMware Work...
background Recently, a leader wanted us to build ...
Many concepts in UI design may seem similar in wo...
Jupyter notebook is configured under the docker c...
This article uses examples to describe the introd...
Table of contents Scenario Requirements glibc ver...
Copy code The code is as follows: <!--[if !IE]...
Table of contents Overview Property settings Proc...
I don’t know why, but UI likes to design honeycom...
Overlay network analysis Built-in cross-host netw...