响应式菜单 flexnav

 

官网:http://jasonweaver.name/lab/flexiblenavigation/

 

Font Awesome 完美的图标字体

 

jQuery延迟误操作插件-hoverIntent

 

respond.js

参考资料:

HTML5 respond.js 解决IE6~8的响应式布局问题

 

 

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>flexnav</title>

    <link rel="stylesheet" href="css/flexnav.css">
    <link rel="stylesheet" href="css/page.css">
    <link rel="stylesheet" href="css/font-awesome.css">
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.hoverIntent.js"></script>
    <script src="js/jquery.flexnav.js"></script>

    <script type="text/javascript">
        $(function () {
            $(".flexnav").flexNav({
                'calcItemWidths': true,
                'hoverIntent': true
            });
        });
    </script>

    <!--[if lt IE 9]>
    <script src="js/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<header>

    <nav>
        <div class="menu-button">
            导航菜单
            <span class="touch-button"><i class="navicon icon-reorder"></i></span>
        </div>
        <ul data-breakpoint="800" class="flexnav">
            <li><a href='#'>主页</a></li>
            <li><a href='#'>我们的愿景</a></li>
            <li><a href='#'>雄狮系统</a></li>
            <li>
                <a href='#'>雄狮学院</a>
                <ul>
                    <li><a href='#'>学院信息</a></li>
                    <li><a href='#'>学院住宿</a></li>
                    <li><a href='#'>学院教练</a></li>
                    <li><a href='#'>优秀球员</a></li>
                    <li><a href='#'>足球及教育体系</a></li>
                </ul>
            </li>
            <li><a href='#'>我们的团队</a></li>
            <li>
                <a href='#'>课程</a>
                <ul>
                    <li><a href='#'>英国夏令营</a></li>
                    <li><a href='#'>中国夏令营</a></li>
                    <li>
                        <a href='#'>短期课程</a>
                        <ul>
                            <li><a href='#'>短期课程( 6星期)</a></li>
                            <li><a href='#'>短期课程(8星期)</a></li>
                            <li><a href='#'>短期课程(12星期)</a></li>
                        </ul>
                    </li>
                    <li>
                        <a href='#'>长期课程</a>
                        <ul>
                            <li><a href='#'>长期课程(一年)</a></li>
                            <li><a href='#'>长期课程(两年)</a></li>
                            <li><a href='#'>教练员培训</a></li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li><a href='#'>商业机遇</a></li>
            <li><a href='#'>新闻</a></li>
            <li><a href='#'>联系方式</a></li>
        </ul>
    </nav>
</header>
</body>
</html>

 

.flexnav .touch-button {
    position: absolute;
    z-index: 999;
    top: 0;
    right: 0;
    width: 50px;
    height: 50px;
    display: inline-block;
    background: #acaca1;
    background: rgba(0, 0, 0, 0.075);
    text-align: center;
    -webkit-border-radius: 50%;
    -moz-border-radius:50%;
    border-radius: 50%;
}

@media all and (min-width: 800px) {
    .flexnav .touch-button {
        border-radius:0;
    }
}

 

 

/*
 FlexNav.js 1.3.3

 Created by Jason Weaver http://jasonweaver.name
 Released under http://unlicense.org/

 //
 */


(function () {
    var $;

    $ = jQuery;

    $.fn.flexNav = function (options) {
        var $nav, $top_nav_items, breakpoint, count, nav_percent, nav_width, resetMenu, resizer, settings, showMenu, toggle_selector, touch_selector, navicon_icon;
        settings = $.extend({
            'animationSpeed': 250,               // 默认的下拉动画速度
            'transitionOpacity': true,          // 默认为不透明动画
            'buttonSelector': '.menu-button',  //默认的菜单按钮CSS类名
            'hoverIntent': false,               //默认的菜单按钮CSS类名
            'hoverIntentTimeout': 150,          // hoverIntent默认结束时间
            'calcItemWidths': false,            // 是否动态配置顶级导航项宽度
            'hover': true                        // 是否支持鼠标悬浮功能
        }, options);
        $nav = $(this);
        $nav.addClass('with-js');
        if (settings.transitionOpacity === true) {
            $nav.addClass('opacity');
        }
        $nav.find("li").each(function () {
            if ($(this).has("ul").length) {
                return $(this).addClass("item-with-ul").find("ul").hide();
            }
        });
        if (settings.calcItemWidths === true) {
            $top_nav_items = $nav.find('>li');
            count = $top_nav_items.length;
            nav_width = 100 / count;
            nav_percent = nav_width + "%";
        }
        if ($nav.data('breakpoint')) {
            breakpoint = $nav.data('breakpoint');
        }
        showMenu = function () {
            if ($nav.hasClass('lg-screen') === true && settings.hover === true) {
                if (settings.transitionOpacity === true) {
                    return $(this).find('>ul').addClass('flexnav-show').stop(true, true).animate({
                        height: ["toggle", "swing"],
                        opacity: "toggle"
                    }, settings.animationSpeed);
                } else {
                    return $(this).find('>ul').addClass('flexnav-show').stop(true, true).animate({
                        height: ["toggle", "swing"]
                    }, settings.animationSpeed);
                }
            }
        };
        resetMenu = function () {
            if ($nav.hasClass('lg-screen') === true && $(this).find('>ul').hasClass('flexnav-show') === true && settings.hover === true) {
                if (settings.transitionOpacity === true) {
                    return $(this).find('>ul').removeClass('flexnav-show').stop(true, true).animate({
                        height: ["toggle", "swing"],
                        opacity: "toggle"
                    }, settings.animationSpeed);
                } else {
                    return $(this).find('>ul').removeClass('flexnav-show').stop(true, true).animate({
                        height: ["toggle", "swing"]
                    }, settings.animationSpeed);
                }
            }
        };
        resizer = function () {
            var selector;
            // console.log(breakpoint);
            // console.log($(window).width());
            if ($(window).width() <= breakpoint) {
                $nav.removeClass("lg-screen").addClass("sm-screen");
                if (settings.calcItemWidths === true) {
                    $top_nav_items.css('width', '100%');
                }
                selector = settings['buttonSelector'] + ', ' + settings['buttonSelector'] + ' .touch-button';
                $(selector).removeClass('active');
                //重置下级菜单点击图标
                $('.item-with-ul ul .navicon').removeClass("icon-chevron-right").addClass("icon-chevron-down");
                return $('.one-page li a').on('click', function () {
                    return $nav.removeClass('flexnav-show');
                });
            } else if ($(window).width() > breakpoint) {
                $nav.removeClass("sm-screen").addClass("lg-screen");
                if (settings.calcItemWidths === true) {
                    $top_nav_items.css('width', nav_percent);
                }
                $nav.removeClass('flexnav-show').find('.item-with-ul').on();

                $('.item-with-ul').find('ul').removeClass('flexnav-show')
                    .find(".navicon").removeClass("icon-chevron-down").addClass("icon-chevron-right");  //重置下级菜单点击图标
                resetMenu();
                if (settings.hoverIntent === true) {
                    return $('.item-with-ul').hoverIntent({
                        over: showMenu,
                        out: resetMenu,
                        timeout: settings.hoverIntentTimeout
                    });
                } else if (settings.hoverIntent === false) {
                    return $('.item-with-ul').on('mouseenter', showMenu).on('mouseleave', resetMenu);
                }
            }
        };
        $(settings['buttonSelector']).data('navEl', $nav);

        touch_selector = '.item-with-ul';
        $(touch_selector).append('<span class="touch-button"><i class="navicon icon-chevron-down"></i></span>');
        toggle_selector = settings['buttonSelector'] + ', ' + settings['buttonSelector'] + ' .touch-button';
        $(toggle_selector).on('click', function (e) {
            var $btnParent, $thisNav, bs;
            $(toggle_selector).toggleClass('active');
            e.preventDefault();
            e.stopPropagation();
            bs = settings['buttonSelector'];
            $btnParent = $(this).is(bs) ? $(this) : $(this).parent(bs);
            //菜单切换,切换图标
            if ($btnParent.find(".navicon").hasClass("icon-reorder")) {
                $btnParent.find(".navicon").removeClass("icon-reorder").addClass(" icon-remove");
            }
            else {
                $btnParent.find(".navicon").removeClass("icon-remove").addClass(" icon-reorder");
            }

            $thisNav = $btnParent.data('navEl');
            return $thisNav.toggleClass('flexnav-show');
        });
        $('.touch-button').on('click', function (e) {
            var $sub, $touchButton;
            $sub = $(this).parent('.item-with-ul').find('>ul');
            $touchButton = $(this).parent('.item-with-ul').find('>span.touch-button');
            if ($nav.hasClass('lg-screen') === true) {
                $(this).parent('.item-with-ul').siblings().find('ul.flexnav-show').removeClass('flexnav-show').hide();
            }
            if ($sub.hasClass('flexnav-show') === true) {
                $sub.removeClass('flexnav-show').slideUp(settings.animationSpeed);
                return $touchButton.removeClass('active');
            } else if ($sub.hasClass('flexnav-show') === false) {
                $sub.addClass('flexnav-show').slideDown(settings.animationSpeed);
                return $touchButton.addClass('active');
            }
        });
        $nav.find('.item-with-ul *').focus(function () {
            $(this).parent('.item-with-ul').parent().find(".open").not(this).removeClass("open").hide();
            return $(this).parent('.item-with-ul').find('>ul').addClass("open").show();
        });
        resizer();
        return $(window).on('resize', resizer);
    };

}).call(this);

 

转载于:https://www.cnblogs.com/linyongqin/articles/6731139.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: element响应式菜单是一种能够根据不同屏幕尺寸自动调整布局和样式的菜单组件。它是基于Element UI框架开发的,具有强大的可定制性和易用性。 element响应式菜单的特点包括: 1. 自适应布局:当页面显示在不同设备上时,element响应式菜单能够根据屏幕尺寸自动调整菜单的展示方式,保证在不同设备上都能够有良好的显示效果。 2. 高度可定制性:element响应式菜单提供了丰富的自定义选项,可以根据项目需求进行菜单内容、样式、布局等方面的定制,满足各种不同的设计要求。 3. 多种菜单类型:element响应式菜单支持多种类型的菜单,如水平菜单、垂直菜单、折叠菜单等,可以根据项目需要选择合适的菜单类型。 4. 交互友好:element响应式菜单提供了丰富的交互效果,如鼠标悬停、点击展开、折叠动画等,使用户与菜单的交互更加友好和流畅。 使用element响应式菜单可以有效提升网页的易用性和用户体验,在不同设备上都能够展示出优秀的浏览效果。同时,element响应式菜单的开发和调整也相对简便,使得项目的开发效率得到提升。无论是响应式网页设计还是移动端开发,element响应式菜单都是一个极为方便和实用的工具。 ### 回答2: Element是一款基于Vue.js开发的响应式UI框架,其中包括了一系列的组件,如菜单组件。Element的响应式菜单提供了一种便捷的方式来创建适应不同屏幕大小的菜单。 Element的响应式菜单可以根据屏幕的宽度自动调整菜单的显示方式和布局,以适应不同的设备和屏幕尺寸。当屏幕宽度较小时,菜单会以折叠的形式展示,并提供一个折叠按钮,点击按钮可以展开或折叠菜单。这样可以节省空间并提升用户体验,使菜单在移动设备上也能够方便使用。 Element的响应式菜单还支持多级菜单的展示,可以实现更复杂的菜单结构。通过给菜单项添加子菜单,可以创建多级菜单,方便用户在复杂的业务场景中进行导航。 使用Element的响应式菜单非常简便,只需要在Vue实例中引入Menu组件,并设置菜单项的相关属性,如图标、标题和路由链接等即可。通过灵活的配置,可以轻松实现各种复杂的菜单样式和动态调整。 总之,Element的响应式菜单为开发者提供了一种方便实用的解决方案,使得创建适应不同屏幕大小的响应式菜单变得更加简单和高效。无论是在PC端还是移动设备上,Element的响应式菜单都能够提供良好的用户体验。 ### 回答3: Element响应式菜单是一种能够根据用户设备屏幕尺寸自动调整布局的菜单组件。它可以在不同的设备上提供良好的用户体验,包括桌面、平板和手机等。 Element响应式菜单的特点之一是支持多种样式和布局。用户可以根据自己的需求选择不同的风格和布局,如水平菜单、垂直菜单、抽屉式菜单等。这样可以为不同的网站或应用程序定制独特的菜单样式,增强用户体验。 另一个特点是支持多级菜单。Element响应式菜单可以承载多级菜单,用户可以通过鼠标或手指滑动来查看更深层次的菜单内容。这种设计可以帮助用户更好地组织和浏览大量的菜单选项,提供更便捷的导航和操作方式。 此外,Element响应式菜单还具有良好的兼容性和扩展性。它适用于各种现代浏览器,并能够适应未来的新技术。同时,Element菜单组件还提供了丰富的功能和API,开发人员可以根据自己的需求进行进一步的定制和扩展。 总之,Element响应式菜单是一种功能强大、灵活多样、用户友好的菜单组件,可以满足不同设备和用户的需求,提供良好的交互体验。无论是个人网站,企业门户还是移动应用程序,都可以考虑使用Element响应式菜单来提升用户界面的质量。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值