jQuery后台左侧多级下拉菜单代码

来源:https://www.sucaihuo.com/js/1431.html 2017-03-08 07:23浏览(2310) 收藏

管理员后台左侧导航下拉多级菜单,jQuery支持二级菜单和三级菜单的sidemenu插件,而且有各式各样的ui图标。
jQuery后台左侧多级下拉菜单代码
分类:导航菜单 > 多级菜单 难易:初级
查看演示 下载资源 下载积分: 30 积分
关注公众号,免费赠送安装视频教程、环境和学习视频,后面会不断更新。

sidemenu多级下拉菜单插件

$.sidebarMenu = function(menu) {
  var animationSpeed = 300;
  
  $(menu).on('click', 'li a', function(e) {
    var $this = $(this);
    var checkElement = $this.next();

    if (checkElement.is('.treeview-menu') && checkElement.is(':visible')) {
      checkElement.slideUp(animationSpeed, function() {
        checkElement.removeClass('menu-open');
      });
      checkElement.parent("li").removeClass("active");
    }

    //If the menu is not visible
    else if ((checkElement.is('.treeview-menu')) && (!checkElement.is(':visible'))) {
      //Get the parent menu
      var parent = $this.parents('ul').first();
      //Close all open menus within the parent
      var ul = parent.find('ul:visible').slideUp(animationSpeed);
      //Remove the menu-open class from the parent
      ul.removeClass('menu-open');
      //Get the parent li
      var parent_li = $this.parent("li");

      //Open the target menu and add the menu-open class
      checkElement.slideDown(animationSpeed, function() {
        //Add the class active to the parent li
        checkElement.addClass('menu-open');
        parent.find('li.active').removeClass('active');
        parent_li.addClass('active');
      });
    }
    //if this isn't a link, prevent the page from being redirected
    if (checkElement.is('.treeview-menu')) {
      e.preventDefault();
    }
  });
}

调用插件方法

$.sidebarMenu($('.sidebar-menu'))
标签: 菜单多级后台
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2