How to make a sidebar menu like this site?
That three subitems of the menu were always visible, and when clicking on the big title of the menu it was shown completely.
How to make a sidebar menu like this site?
That three subitems of the menu were always visible, and when clicking on the big title of the menu it was shown completely.
Through css, pre-hide all elements starting from the fifth .item:nth-child(+n+5)
Hide and expand all items, starting from the fourth $('.item').slice(4)
Apparently in css the order starts from 1 , and in js from 0
$('.item').eq(0).click(function() { $(this).html() == '↓ список' ? $(this).html('↑ список') : $(this).html('↓ список'); $('.item').slice(4).slideToggle(); }); .item { list-style: none; background: #E0E4E8; padding: 2px 4px 2px 4px; cursor: pointer; } .item:hover { background: #F4F8FB; } .list { display: list-item; } #list { cursor: pointer; } .item:nth-child(+n+5) { display: none; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script> <ul style='width: 256px'> <li class='item'>↓ список</li> <li class='item'>item 1</li> <li class='item'>item 2</li> <li class='item'>item 3</li> <li class='item'>item 4</li> <li class='item'>item 5</li> <li class='item'>item 6</li> </ul> $(function(){ $(".title").click(function () { $(".content").toggle("slow"); }); }); .content { display: none; } <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="title">Title</div> <div class="mini-content"> <p>Пункт - 1</p> <p>Пункт - 2</p> <p>Пункт - 3</p> <div class="content"> <p>Пункт - 4</p> <p>Пункт - 5</p> <p>Пункт - 6</p> <p>Пункт - 7</p> <p>Пункт - 8</p> <p>Пункт - 9</p> </div> </div> Source: https://ru.stackoverflow.com/questions/539088/
All Articles