This article shares the specific code of JavaScript to realize the appearance of submenu on click for your reference. The specific content is as follows First, let's take a look at the effect of clicking on the submenu as shown below: Click the yellow button and a submenu will appear as shown below: Let's take a look at the layout first: <div class="menu"> <div class="sign" id="sign"></div> <div class="lis" id="lis"> <ul> <li><a href="">one</a></li> <li><a href="">two</a></li> <li><a href="">three</a></li> <li><a href="">four</a></li> <li><a href="">five</a></li> </ul> </div> </div> The CSS styles are as follows: ul{ padding-inline-start: 0px; } .menu{ margin: 0 auto; background:#0DA795; height: 40px; width: 600px; } .sign{ width: 30px; float: right; margin-right: 20px; margin-top: 8px; height: 25px; background: rgba(243,193,63,1.00); border-radius: 5px; position: relative; cursor: pointer; //Set the cursor to the shape of a hand} .lis{ position: absolute; top:30px; display: none; } .lis ul li{ list-style: none; width: 600px; line-height: 40px; font-size: 14px; text-align: center; border-bottom: 1px solid #565656; background:#EAEDD5; }.lis a{ text-decoration: none; color: black; } .lis a:hover{ color: #0da759; } Pay special attention to position in CSS styles. The JavaScript part is as follows: 1. Get their IDs first. After getting their IDs, add a click event to the first ID (sigin) through OnClick; This achieves the effect we want, see the implementation code: <script> var biaozhi=document.getElementById("sign"); var li = document.getElementById("lis"); biaozhi.onclick=function(){ var i=li.style.display; if (i=="none"){ li.style.display="block";//First statement}else{ li.style.display="none"; //Second statement} } </script> 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:
|
<<: MySQL inspection script (must read)
>>: Scary Halloween Linux Commands
Table of contents 1. Project Requirements Second,...
This article takes Centos7.6 system and Oracle11g...
The specific code is as follows: <a href="...
constraint Constraints ensure data integrity and ...
1. System installation package yum -y install mak...
Preface When I was working on a project recently,...
This article shares the installation steps and us...
Table of contents 1. From father to son 2. From s...
nvm nvm is responsible for managing multiple vers...
Preface To put it simply, tcpdump is a packet ana...
Because a certain function of my project requires...
Table of contents ReactRouterV6 Changes 1. <Sw...
The <base> tag specifies the default addres...
Content Detail Tags: <h1>~<h6>Title T...
In some interview experiences, you can often see ...