The side menu of the accordion implemented by jQuery, jquery accordion
This article describes the effect of the accordion side menu implemented by jQuery. We will share this with you for your reference. The details are as follows:
The following is a simple accordion menu ,:
Click B to compress the C list, and click C to change the style of its own and its parent node B. Different styles are changed during suspension.
First look at the page code, nesting of the list:
<div id="menuDiv"><ul id="menu"><li class="parentLi"><span>B</span><ul class="childrenUl"><li class="childrenLi"><span>C</span></li><li class="childrenLi"><span>C</span></li><li class="childrenLi"><span>C</span></li></ul></li><li class="parentLi"><span>B</span><ul class="childrenUl"><li class="childrenLi"><span>C</span></li><li class="childrenLi"><span>C</span></li><li class="childrenLi"><span>C</span></li></ul></li><li class="parentLi"><span>B</span><ul class="childrenUl"><li class="childrenLi"><span>C</span></li><li class="childrenLi"><span>C</span></li><li class="childrenLi"><span>C</span></li></ul></li></ul></div>
Css code, mainly set the background color and the Left Border style of the sub-menu, set the floating and selected style, and start to set the sub-menu not to display (click through js settings and then display ):
#menuDiv{ width: 200px; background-color: #029FD4;}.parentLi{ width: 100%; line-height: 40px; margin-top: 1px; background: #1C73BA; color: #fff; cursor: pointer; font-weight:bolder;}.parentLi span{ padding: 10px;}.parentLi:hover, .selectedParentMenu{ background: #0033CC;}.childrenUl{ background-color: #ffffff; display: none;}.childrenLi{ width: 100%; line-height: 30px; font-size: .9em; margin-top: 1px; background: #63B8FF; color: #000000; padding-left: 15px; cursor: pointer;}.childrenLi:hover, .selectedChildrenMenu{ border-left: 5px #0033CC solid; background: #0099CC; padding-left: 15px;}
Next, click the Event code:
$(".parentLi").click(function(event) { $(this).children('.childrenUl').slideToggle();});$(".childrenLi").click(function(event) { event.stopPropagation(); $(".childrenLi").removeClass('selectedChildrenMenu'); $(".parentLi").removeClass('selectedParentMenu'); $(this).parents(".parentLi").addClass('selectedParentMenu'); $(this).addClass('selectedChildrenMenu');});
It should be noted that the list nesting will cause event bubbles, so the click event in the sub-menu should organize bubbles, event. stopPropagation (); For details, see API