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 Preface 1. Rendering 2. Code 3....
This article describes the mysql show operation w...
<body style="scroll:no"> <tabl...
0. Preliminary preparation Disable secure boot in...
console.log( [] == ![] ) // true console.log( {} ...
Summary of common functions of PostgreSQL regular...
1. Construction components 1. A form must contain...
Table of contents background Problem Description ...
Table of contents Preface Check Constraints Creat...
Table of contents Basic HTML structure Generate s...
Table of contents Project Creation Project Struct...
Table of contents background Achieve a similar ef...
Achieve results Implementation Code html <h1 c...
This article example shares the specific code of ...
This article example shares the specific code of ...