Navigation bar actions--show and hide lists and add styles

Source: Internet
Author: User

First, make sure that the parent class of the navigation bar is bui-side-menu, each need to show and hide the list by child1 (before child, after the number named), and add the attribute data-submenu= ' 1 ' to the clicked parent list; Add the active class style to the a tag.

Next, write jquery.

Example:

HTML code:

<ul class= "Bui-side-menu bui-menu" style= "height:100%" >
	<li class= "Bui-menu-item Menu-second" >
		<div class= "Bui-menu-title" >
			<a data-submenu= "1" href= "javascript:void (0);" >
				<span class= "Bui-menu-title-text" > Parent list </span>
			</a>					
		</div>
		<ul id= "Child1" class= "Bui-menu" style= "Display:none" >
			<li class= "Bui-menu-item menu-leaf" >
				<a href= " Http://localhost/AppAdmin/index.php?m=UserData&act=newAddShow&timeStart&timeEnd&dateType "> <em> Sub-list </em></a>
			</li>
		</ul>
	</li>
</ul>


jquery Code:

$ (function () {
	//Left nav bar
	var menu = $ ('. Bui-side-menu '). On (' Click ', ' a ', function () {
		menu.find (' a '). Removeclass (' active ')
		var submenu = $ (this). Data (' submenu ');
		if (submenu) {
			submenu = $ (' #child ' +submenu);
			if (submenu.is (': Hidden ')) {
				submenu.show ();
				$ (this). addclass (' active ')
			}else{
				submenu.hide ();
				$ (this). Removeclass (' active ');
			}
		} else{
			$ (this). addclass (' active ');}})


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.