SoFunction
Updated on 2025-02-28

js implements the example code for shrinking menu effect


<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." type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
//Hide the menu directly at the beginning
            $(".content").hide();
//Add a click event to the title
            $(".tit").click(function () {
//When clicked, open the menu, and other menus are hidden
                $(this).next().slideDown().parent().siblings().children(".content").slideUp();
}).first().next().slideDown();//The first menu opens after default
        });
    </script>
</head>
<body>
    <div>
        <ul class="menu">
<li class="tit">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">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">Menu 3</li>
            <li class="content">
                <ul>
                    <li>22222</li>
                    <li>22222</li>
                    <li>22222</li>
                    <li>22222</li>
                </ul>
            </li>
        </ul>
    </div>
</body>