Js implementation of the menu effect instance code
- 2020-03-26 21:40:54
- OfStack
Without further ado, go straight to the code: there are comments
<head>
<title></title>
<style type="text/css">
div
{
border: 1px solid black;
width: 100px;
}
ul .tit, .content
{
list-style-type: none;
}
.menu
{
padding: 0px;
margin: 0px;
}
.tit
{
background-color:#0094ff;
color:White;
padding:2px 10px;
cursor:pointer;
}
</style>
<script src="js/jquery-1.9.0.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
//Hide the menu at first
$(".content").hide();
//Add a click event to the title
$(".tit").click(function () {
//When clicked, open the menu while other menus are hidden
$(this).next().slideDown().parent().siblings().children(".content").slideUp();
}).first().next().slideDown();//The first menu opens by default
});
</script>
</head>
<body>
<div>
<ul class="menu">
<li class="tit"> The menu 1</li>
<li class="content">
<ul>
<li>11111</li>
<li>11111</li>
<li>11111</li>
<li>11111</li>
</ul>
</li>
</ul>
<ul class="menu">
<li class="tit"> The menu 2</li>
<li class="content">
<ul>
<li>22222</li>
<li>22222</li>
<li>22222</li>
<li>22222</li>
</ul>
</li>
</ul>
<ul class="menu">
<li class="tit"> The menu 3</li>
<li class="content">
<ul>
<li>22222</li>
<li>22222</li>
<li>22222</li>
<li>22222</li>
</ul>
</li>
</ul>
</div>
</body>