html5演示6种不同的响应式图标菜单

来源:https://www.sucaihuo.com/js/740.html 2016-02-05 20:49浏览(1171) 收藏

本文演示了6种不同的手机菜单效果,用手机浏览器查看,效果会更好。
html5演示6种不同的响应式图标菜单
分类:导航菜单 > 分类导航 难易:中级
查看演示 下载资源 下载积分: 20 积分

导航菜单html代码 包括图标和标题

<nav id="menu" class="nav">					
    <ul>
        <li>
            <a href="http://www.sucaihuo.com/">
                <span class="icon">
                    <i aria-hidden="true" class="icon-home"></i>
                </span>
                <span>首页</span>
            </a>
        </li>
        <li>
            <a href="http://www.sucaihuo.com/js">
                <span class="icon"> 
                    <i aria-hidden="true" class="icon-services"></i>
                </span>
                <span>服务</span>
            </a>
        </li>
        <li>
            <a href="http://www.sucaihuo.com/templates">
                <span class="icon">
                    <i aria-hidden="true" class="icon-portfolio"></i>
                </span>
                <span>文件夹</span>
            </a>
        </li>
        <li>
            <a href="http://www.sucaihuo.com/php">
                <span class="icon">
                    <i aria-hidden="true" class="icon-blog"></i>
                </span>
                <span>博客</span>
            </a>
        </li>
        <li>
            <a href="http://www.sucaihuo.com/help/template">
                <span class="icon">
                    <i aria-hidden="true" class="icon-team"></i>
                </span>
                <span>团队</span>
            </a>
        </li>
        <li>
            <a href="http://www.sucaihuo.com/tools">
                <span class="icon">
                    <i aria-hidden="true" class="icon-contact"></i>
                </span>
                <span>联系我们</span>
            </a>
        </li>
    </ul>
</nav>
//  The function to change the class
var changeClass = function(r, className1, className2) {
    var regex = new RegExp("(?:^|\\s+)" + className1 + "(?:\\s+|$)");
    if (regex.test(r.className)) {
        r.className = r.className.replace(regex, ' ' + className2 + ' ');
    }
    else {
        r.className = r.className.replace(new RegExp("(?:^|\\s+)" + className2 + "(?:\\s+|$)"), ' ' + className1 + ' ');
    }
    return r.className;
};

//  Creating our button in JS for smaller screens
var menuElements = document.getElementById('menu');
menuElements.insertAdjacentHTML('afterBegin', '<button type="button" id="menutoggle" class="navtoogle" aria-hidden="true"><i aria-hidden="true" class="icon-menu"> </i> Menu</button>');

//  Toggle the class on click to show / hide the menu
document.getElementById('menutoggle').onclick = function() {
    changeClass(this, 'navtoogle active', 'navtoogle');
}

// http://tympanus.net/sucaihuo/2013/05/08/responsive-retina-ready-menu/comment-page-2/#comment-438918
document.onclick = function(e) {
    var mobileButton = document.getElementById('menutoggle'),
            buttonStyle = mobileButton.currentStyle ? mobileButton.currentStyle.display : getComputedStyle(mobileButton, null).display;

    if (buttonStyle === 'block' && e.target !== mobileButton && new RegExp(' ' + 'active' + ' ').test(' ' + mobileButton.className + ' ')) {
        changeClass(mobileButton, 'navtoogle active', 'navtoogle');
    }
}
标签: 导航菜单图标
评论0
头像

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

1 2