Home >Web Front-end >JS Tutorial >js implementation of shrink menu effect example code_javascript skills
This article introduces the example code of js to achieve the shrink menu effect. Friends in need can refer to it
No further nonsense, just go to the code: There are comments
<head> <title></title> <style type="text/css"> p { 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 () { //一开始直接隐藏菜单 $(".content").hide(); //给标题添加点击事件 $(".tit").click(function () { //当点击的时候,打开菜单,同时其他的菜单隐藏 $(this).next().slideDown().parent().siblings().children(".content").slideUp(); }).first().next().slideDown();//默认之后第一个菜单打开 }); </script> </head> <body> <p> <ul class="menu"> <li class="tit">菜单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">菜单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">菜单3</li> <li class="content"> <ul> <li>22222</li> <li>22222</li> <li>22222</li> <li>22222</li> </ul> </li> </ul> </p> </body>