The specific code for implementing the retractable secondary menu in JavaScript is for your reference. The specific content is as follows Retractable secondary menu: Case description: The effect diagram is as follows. Only one can be opened at a time. After opening, the + sign changes to -. HTML Code <!--Pull list--> <style> li { /*Cancel the li dot*/ list-style: none; } li span { /*Set the background image for the span tag (small plus and minus signs at the beginning, no-repeat, initial position 0 0)*/ background: url(add.png) no-repeat left center; padding-left: 20px; } /*Starting style*/ li ul{ height: 0; /*Overflow hidden*/ overflow: hidden; /*Add transition effect*/ transition: all 0.5s; } /*Expand style*/ .open{ background-image: url(minus.png); } .open+ul{ height: 70px; } </style> <ul class="tree"> <li><span class="open">Attendance Management</span> <ul> <li>Daily Attendance</li> <li>Leave Application</li> <li>Overtime business trip</li> </ul> </li> <li><span>Information Center</span> <ul> <li>Daily Attendance</li> <li>Leave Application</li> <li>Overtime business trip</li> </ul> </li> <li><span>Collaborative Office</span> <ul> <li>Daily Attendance</li> <li>Leave Application</li> <li>Overtime business trip</li> </ul> </li> </ul> <script src="mJS.js"></script> JavaScript code // Pull-out list // Implementation ideas: var spans = document.querySelectorAll(".tree span"); for (var i = 0; i < spans.length; i++) { spans[i].onclick = function () { // console.log(this); // Find the element span to be modified // Modify, delete or add class -> open // Check if there is an open on itself, if so, delete it! // this -> points to the element that triggered the event if (this.className == "open") { // If there is, delete it! this.className = ""; } else { // If not, add it and delete the others that are already opened! //Find the open (li of the open attribute) var openSpan = document.querySelector(".tree.open") if (openSpan !== null) { // If the collection is not empty, delete their open attribute openSpan.className = ""; } // Set the open attribute for yourself this.className = "open"; } } } 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:
|
<<: In-depth understanding of the use of r2dbc in MySQL
>>: How to set background blur with CSS
After being tortured by the front-end cross-domai...
This article introduces an example of how CSS3 ca...
0 Differences between icons and images Icons are ...
MySQL is a very powerful relational database. How...
<br />Original article: http://www.alistapar...
Table of contents Preface Install vue-i18n Config...
This article shares the MySQL installation and co...
When using jquery-multiselect (a control that tra...
For many people who are new to HTML, table <ta...
Copy code The code is as follows: <!--doctype ...
This article shares the specific code of js to ac...
1. What is Parallax scrolling refers to the movem...
This article is original by 123WORDPRESS.COM Ligh...
Recently, due to business adjustments in the comp...
vue-cli uses stimulsoft.reports.js (nanny-level t...