In actual web page development, accordions also appear frequently. I made a simple accordion, but I felt that its transition effect was not realized, and the content list appeared abruptly. The effect picture is as follows: The implementation code is as follows: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Accordion</title> <style> body, ul { padding: 0; margin: 0; } li { list-style: none; } .nav { width: 150px; height: 310px; margin-top: 30px; margin-left: 50px; font-size: 20px; border: 1px solid #ccc; } .nav>ul>li:nth-child(2n+1) { background-color: cadetblue; } .nav>ul>li:nth-child(2n+2) { height: 160px; display: none; transition: all 1s; } .nav>ul>#selected { background-color: rgb(46, 115, 117); } .nav>ul>li:nth-child(2) { display: block; } </style> </head> <body> <div class="nav"> <ul> <li id="selected">Title 1</li> <li> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </li> <li>Title 2</li> <li> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </li> <li>Title 3</li> <li> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </li> <li>Heading 4</li> <li> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </li> <li>Title 5</li> <li> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </li> <li>Title 6</li> <li> <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> </ul> </li> </ul> </div> <script> var title = document.querySelectorAll(".nav>ul>li:nth-child(2n+1)"); for (var i = 0; i < title.length; i++) { title[i].onmouseover = function () { for (var j = 0; j < title.length; j++) { title[j].nextElementSibling.style.display = "none"; title[j].id = ""; } this.id = "selected"; this.nextElementSibling.style.display = "block"; } } </script> </body> </html> The transition effect is added with code: transition: all 1s; 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:
|
<<: Detailed tutorial for downloading, installing and configuring MySQL 5.7.27
>>: Detailed explanation of Nginx Rewrite usage scenarios and code examples
The benefits of using MySQL master-slave replicat...
This article shares with you the graphic tutorial...
1 Download the MySQL 5.6 version compressed packa...
Preface <br />In the previous article "...
Table of contents 1. Drag effect example 2. CSS I...
When installing packages on an Ubuntu server, you...
This article example shares the specific code of ...
Preface: When designing a table in MySQL, MySQL o...
Problem Description Several machines recently dis...
Table of contents 1. Overview 2. Use docker to de...
1.1 Building the Directory Structure This operati...
Table of contents Preface 1. MySQL enables SSL co...
Preface There is a scenario where, for the sake o...
Table of contents compose function Array.prototyp...
Table of contents environment: 1. Docker enables ...