菜单展开及收缩效果 bootstrap+jquery

        $(".mymenu").click(function () {
            var mymenu = $(this.parentElement);
            $(".treeview-menu").slideUp("slow", function () {
                $(".active").toggleClass("active treeview")
                //收起其他打开的菜单
                $(".glyphicon-menu-down").toggleClass("glyphicon-menu-down glyphicon-menu-left");
            });
            if ($(this.parentElement.lastElementChild).attr("style") == "display: none;" || $(this.parentElement.lastElementChild).attr("style") == undefined) {
                $(this.parentElement.lastElementChild).slideDown("slow", function () {
                    //sidedown收起完成后的操作
                    mymenu.toggleClass("active treeview");
                    //更新图标
                    $(this.parentElement.firstElementChild.lastElementChild).toggleClass("glyphicon-menu-down glyphicon-menu-left");
                });
            }
        });
        $("._menuitem").click(function () {
            $("._menuitem").removeClass("active");
            $(this).toggleClass("active");
        });

HTML

      <ul class="sidebar-menu" id="siderbar-menu">
                    <li class="header">主菜单</li>
                    <li class="treeview">
                        <a href="#" class="mymenu">
                            <i class="glyphicon glyphicon-dashboard"></i> <span>菜单A</span> <span class="glyphicon glyphicon-menu-left pull-right"></span>
                        </a>
                        <ul class="treeview-menu amenu">
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单A1</a></li>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单A2</a></li>
                        </ul>
                    </li>

                    <li class="treeview">
                        <a href="#" class="mymenu">
                            <i class="glyphicon glyphicon-asterisk"></i>
                            <span>菜单B</span>
                            <span class="label label-primary pull-right">4</span>
                        </a>
                        <ul class="treeview-menu">
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单B1</a></li>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单B2</a></li>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单B3</a></li>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单B4</a></li>
                        </ul>

                    </li>
                    <li class="treeview">
                        <a href="#">
                            <i class="glyphicon glyphicon-object-align-vertical"></i>
                            <span>菜单C 无 子菜单</span>
                            <small class="label pull-right bg-green">new</small>
                        </a>
                    </li>
                    <li class="treeview">
                        <a href="#" class="mymenu">
                            <i class="glyphicon glyphicon-blackboard"></i>
                            <span>菜单D</span>
                            <span class="glyphicon glyphicon-menu-left pull-right"></span>
                        </a>
                        <ul class="treeview-menu">
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-green"></i> 菜单D1</a></liclass>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单D2</a></li>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单D3</a></li>
                            <li class="_menuitem"><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> 菜单D4</a></liclass>
                        </ul>
                    </li>
                    <li class="header">图例</li>
                    <li><a href="#"><i class="glyphicon glyphicon-unchecked text-red"></i> <span>重要</span></a></li>
                    <li><a href="#"><i class="glyphicon glyphicon-unchecked text-yellow"></i> <span>警告</span></a></li>
                    <li><a href="#"><i class="glyphicon glyphicon-unchecked text-aqua"></i> <span>消息</span></a></li>
                </ul>

页面效果:

原文地址:https://www.cnblogs.com/daniel-niu/p/10344828.html

时间: 2024-10-19 06:16:32

菜单展开及收缩效果 bootstrap+jquery的相关文章

jquery 菜单展开与收缩参考脚本

/* * metismenu - v1.1.3 * Easy menu jQuery plugin for Twitter Bootstrap 3 * https://github.com/onokumus/metisMenu * * Made by Osman Nuri Okumus * Under MIT License */ ;(function($, window, document, undefined) { var pluginName = "metisMenu", def

第一次来博客园先用jquery写一个简单菜单收缩效果

<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head>    <meta charset="utf-8" />    <title></title>    <script src="jquery-1.7.2.min.js"></script&g

JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果

Ace模板地址:http://code.google.com/p/ace-engine/wiki/AceTemplate(有时会打不开) Ace英文官网:http://wrapbootstrap.com/preview/WB0B30DGR Ace模板功能介绍地址:http://www.cnblogs.com/txw1958/p/Ace-Responsive-Admin-Template.html 一.效果展示 1.初始加载出来的效果 2.展开菜单(支持多级展开,后面代码介绍) 3.点击子菜单,以

JS组件系列——基于Bootstrap Ace模板的菜单和Tab页效果分享(你值得拥有)

前言:最近园子里多了许多谈语言.谈环境.谈逼格(格局)的文章,看看笑笑过后,殊不知其实都是然并卵.提升自己的技术才是王道.之前博主分享过多篇bootstrap组件的文章,引起了很多园友的关注和支持,看样子这种风格还是受到很多园友青睐的.本着不辜负园友们的支持的原则,应群友们的要求,今天来分享下项目中使用Ace模板的菜单样式和基于iframe的Tab页效果. Ace模板地址:http://code.google.com/p/ace-engine/wiki/AceTemplate(有时会打不开) A

jQuery 菜单栏 展开与收缩例子

废话少说,上代码 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>测试 查找下一个元素&l

jQuery鼠标悬停3d菜单展开动画

效果体验:http://hovertree.com/texiao/jquery/93/ 竖直的主菜单贴着页面左侧,当光标移入菜单项时,以3D动画的方式弹出对应的二级菜单.采用jQuery和CSS3实现.支持Chrome,火狐,Edge等浏览器. 效果图: 代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport"

jQuery图片旋转展示收缩效果

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-

jQuery Wheel 环形菜单插件5种效果演示

很酷的菜单-jQuery Wheel 环形菜单插件5种效果演示 在线预览 下载地址 实例代码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 <div class="container">            <!-- Top Navi -->            <div class="header

展开/收缩效果切换

<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>展开/收缩效果切换</title> <style> #box .hid{display:none;} #box .show{display:block;} #tog{cursor: pointer} li{list-style: none} &l