selectmenu实现 支持下拉,分页,键盘操作等功能的下拉菜单效果代码

代码语言:html

所属分类:菜单导航

代码描述:selectmenu实现 支持下拉,分页,键盘操作等功能的下拉菜单效果代码

代码标签: 下拉 , 分页 , 键盘 操作 功能 下拉菜单 效果

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<!DOCTYPE html>
<html lang="zh">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> 
	<meta name="viewport" content="width=device-width, initial-scale=1.0">

	
	<!---基础样式-->
<style>
article,aside,details,figcaption,figure,footer,header,hgroup,main,nav,section,summary{display:block;}audio,canvas,video{display:inline-block;}audio:not([controls]){display:none;height:0;}[hidden]{display:none;}html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;}body{margin:0;}a:focus{outline:thin dotted;}a:active,a:hover{outline:0;}h1{font-size:2em;margin:0.67em 0;}abbr[title]{border-bottom:1px dotted;}b,strong{font-weight:bold;}dfn{font-style:italic;}hr{-moz-box-sizing:content-box;box-sizing:content-box;height:0;}mark{background:#ff0;color:#000;}code,kbd,pre,samp{font-family:monospace,serif;font-size:1em;}pre{white-space:pre-wrap;}q{quotes:"\201C" "\201D" "\2018" "\2019";}small{font-size:80%;}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline;}sup{top:-0.5em;}sub{bottom:-0.25em;}img{border:0;}svg:not(:root){overflow:hidden;}figure{margin:0;}fieldset{border:1px solid #c0c0c0;margin:0 2px;padding:0.35em 0.625em 0.75em;}legend{border:0;padding:0;}button,input,select,textarea{font-family:inherit;font-size:100%;margin:0;}button,input{line-height:normal;}button,select{text-transform:none;}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer;}button[disabled],html input[disabled]{cursor:default;}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0;}input[type="search"]{-webkit-appearance:textfield;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;box-sizing:content-box;}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none;}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0;}textarea{overflow:auto;vertical-align:top;}table{border-collapse:collapse;border-spacing:0;}
    body, html { font-size: 100%; 	padding: 0; margin: 0;}

/* Reset */
*,
*:after,
*:before {
	-webkit-box-sizing: border-box;
	-moz-box-sizing: border-box;
	box-sizing: border-box;
}

/* Clearfix hack by Nicolas Gallagher: http://nicolasgallagher.com/micro-clearfix-hack/ */
.clearfix:before,
.clearfix:after {
	content: " ";
	display: table;
}

.clearfix:after {
	clear: both;
}

body{
	background: #494A5F;
	color: #D5D6E2;
	font-weight: 500;
	font-size: 1.05em;
	font-family: "Microsoft YaHei","Segoe UI", "Lucida Grande", Helvetica, Arial,sans-serif;
}
</style>
	
	<!---图标样式-->
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/bootstrap.3.3.4.css">
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/font-awesome-4.7.0/css/font-awesome.min.css">
	
	<!---代码格式样式,可无视-->
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/SyntaxHighlighter.css">
	
	<!---主要样式-->
<link type="text/css" rel="stylesheet" href="//repo.bfw.wiki/bfwrepo/css/selectmenu.css">
	
</head>
<body>

	<div class="container">
		<h1 class="page-header">下拉菜单插件 <small>支持下拉,分页,键盘操作等功能</small></h1>
		<div class="row-fluid">
			<h2 class="page-header">1.经典使用场景 <small></small></h2>
            <div class="col-md-12">
                <div class="col-md-6">
                    <p><strong>A</strong>. Select your favorite NBA team:
                        <button type="button" class="btn btn-default" id="demoSingle">Select Team</button>
                    </p>
                    <div class="thumbnail">
                        <img id="nbaTeamLogo">
                        <div class="caption">
                            <p id="nabTeamName"></p>
                        </div>
                    </div>
                    <p>The NBA team logo images copyright comes form <a href="" target="_blank">china</a></p>
                </div>
                <div class="col-md-6">
                    <p><strong>B</strong>. Choose teams to follow team news:
                        <button type="button" class="btn btn-default" id="demoMultiple">Select Teams</button>
                    </p>
                    <div class="panel panel-default">
                        <div class="panel-body" id="nbaTeamLists"></div>
                    </div>
                </div>
            </div>
		</div>

        <div class="row-fluid">
            <div class="col-md-12">
                <div class="col-md-6">
                    <p><strong>C</strong>. Which site you want to visit ?</p>
                    <p><button type="button" class="btn btn-default" id="demoBaseMenu">Select Menu <i class="fa fa-caret-down"></i></button></p>
                </div>
                <div class="col-md-6">
                    <p><strong>D</strong>. Menu embedded to page</p>
                    <div id="demoEmbedded"></div>
                </div>
            </div>
        </div>

        <div class="row-fluid">
            <div class="col-md-12">
                <div class="col-md-12">
                    <strong>E</strong>. your mouse right click to call menu
                    <div class="jumbotron" id="demoRightClick">
                        <h2 class="text-center"><i class="fa fa-mouse-pointer"></i> 鼠标右键查看效果</h2>
                    </div>
                </div>
            </div>
        </div>



        <div class="row-fluid">
            <h2 class="page-header">2.1 常规下拉菜单 <small></small></h2>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//菜单使用的数据格式
/**
 * content  [string]   : 菜单项目显示文本,支持HTML格式(设置内容为“sm_divider”可生成分隔栏)
 * header   [boolean]  : 是否为子标题栏
 * url      [string]   : 需要跳转的链接
 * callback [function] : 需要执行的回调函数
 * disabled [boolean]  : 是否禁用菜单项目
 */
var menuData = [
    {content:'News Site',header: true},//定义子标题栏
    {content:'163 NetEase',url : 'http://www.163.com'},//链接跳转型菜单项目
    {content:'sm_divider'},//分隔栏
    //使用HTML的方式设置菜单显示的内容,并定义菜单项目为禁用
    {content:'<i class="fa fa-fw fa-facebook"></i> Facebook',url : 'https://www.facebook.com',disabled : true},
    //点击后执行回调的菜单项目
    {content:'Click this menu item to trigger your callback',callback : function(){
        bDialog.alert('you can do anything in callback!');
    }}
];
]]>
</script>
            <button type="button" class="btn btn-default" id="baseMenu"><i class="fa fa-bars"></i> Select Menu</button>


            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//HTML按钮
<button type="button" id="btnMenu" >Select Team</button>
//javascript 设置
$('#btnMenu').click(function(){
    $(this).selectMenu({
        //设置常规菜单模式
        regular : true,
        data : menuData
    });
});
]]>
            </script>
            <div class="alert alert-info" role="alert">
                示例中,带回调的菜单项目中的弹出窗口为 <a href="https://terryz.github.io/bdialog/index.html" target="_blank"><strong>bDialog</strong></a> 插件
            </div>
        </div>

        <div class="row-fluid">
            <h4 class="heading">2.2 带标题栏的菜单 <small></small></h4>
            <button type="button" class="btn btn-default" id="baseMenuHeader"><i class="fa fa-header"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        title : '<i class="fa fa-fw fa-thumbs-o-up"></i> I can have a title bar',
        regular : true,
        data : menuData
    });
});
]]>
            </script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">2.3 带子标题菜单项目的菜单 <small></small></h4>
            <button type="button" class="btn btn-default" id="baseMenuSubHeader"><i class="fa fa-list-ul"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//设置数据中项目header : true,即可指定为子标题栏
var menuData = [
    {content:'News Site',header: true}
];
//javascript 设置
$('#btnMenu').click(function(){
    $(this).selectMenu({
        regular : true,
        data : menuData
    });
});
]]>
            </script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">2.4 带箭头的菜单 <small></small></h4>
            <button type="button" class="btn btn-default" id="baseMenuArrow"><i class="fa fa-arrow-up"></i> 带箭头的菜单</button>
            <button type="button" class="btn btn-default" id="baseMenuRight"><i class="fa fa-arrow-right"></i> 菜单右对齐</button>
            <button type="button" class="btn btn-default" id="baseMenuCenter"><i class="fa fa-arrow-down"></i> 菜单居中对齐</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        arrow : true,//打开菜单箭头,默认不带箭头
        position : 'right',//可设置'left'(default),'center','right'
        regular : true,
        data : menuData
    });
});
]]>
            </script>
        </div>


        <div class="row-fluid">
            <h2 class="page-header">3.1 高级下拉菜单 <small></small></h2>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//菜单使用的示例数据格式
//数据格式与常规菜单模式的固定格式不同,该模式下,数据格式可以完全自定义
//并通过设置keyField、showField、searchField等参数进行指定具体使用的数据节点
var selectMenuData = [
    {id:1 ,name:'Chicago Bulls',desc:'芝加哥公牛',abbr:'CHI'},
    {id:2 ,name:'Cleveland Cavaliers',desc:'克里夫兰骑士',abbr:'CLE'},
    {id:3 ,name:'Detroit Pistons',desc:'底特律活塞',abbr:'DET'},
    {id:4 ,name:'Indiana Pacers',desc:'印第安纳步行者',abbr:'IND'},
    {id:5 ,name:'Milwaukee Bucks',desc:'密尔沃基雄鹿',abbr:'MIL'}
];
]]>
            </script>
            <button type="button" class="btn btn-default" id="selectMenuBase"><i class="fa fa-server"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//HTML按钮
<button type="button" id="btnMenu" >Select Team</button>
//javascript 设置
$('#btnMenu').click(function(){
    $(this).selectMenu({
        showField : 'name',//指定显示文本的字段
        keyField : 'id',//指定id的字段
        data : selectMenuData
    });
});
]]>
</script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">3.2 不需要快速搜索的下拉菜单 <small></small></h4>
            <button type="button" class="btn btn-default" id="selectMenuNoSearch"><i class="fa fa-server"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        showField : 'name',
        keyField : 'id',
        search : false,//关闭搜索栏
        data : selectMenuData
    });
});
]]>
</script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">3.3 指定菜单显示项目个数 <small></small></h4>
            <button type="button" class="btn btn-default" id="selectMenuListSize"><i class="fa fa-server"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        showField : 'name',
        keyField : 'id',
        search : false,
        title : false,//关闭标题栏
        listSize : 5,//设置显示的菜单项目个数(菜单高度)
        data : selectMenuData
    });
});
]]>
</script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">3.4 多分组数据下拉菜单、多选模式 <small></small></h4>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//多分组格式数据,要求数据必须按照以下格式设置,但list节点内的数据,与不分组的数据格式一样,可以自由定义
var selectMenuGroupData = [{
    title : 'East',
    list :[
        {id:1 ,name:'Chicago Bulls',desc:'芝加哥公牛',abbr:'CHI'},
        {id:2 ,name:'Cleveland Cavaliers',desc:'克里夫兰骑士',abbr:'CLE'}
    ]
},{
    title : 'West',
    list : [
        {id:16,name:'Denver Nuggets',desc:'丹佛掘金',abbr:'DEN'},
        {id:17,name:'Minnesota Timberwolves',desc:'明尼苏达森林狼',abbr:'MIN'}
    ]}
];
]]>
            </script>
            <button type="button" class="btn btn-default" id="selectMenuGroup"><i class="fa fa-server"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        showField : 'name',
        keyField : 'id',
        multiple : true,//打开多选模式
        data : selectMenuGroupData
    });
});
]]>
</script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">3.5 初始化选中项目 <small></small></h4>
            <button type="button" class="btn btn-default" id="selectMenuInit"><i class="fa fa-server"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        showField : 'name',
        keyField : 'id',
        arrow : true,
        initSelected : 1,
        data : selectMenuData
    });
});
]]>
</script>
        </div>

        <div class="row-fluid">
            <h4 class="heading">3.6 自定义项目显示模板 <small></small></h4>
            <button type="button" class="btn btn-default" id="selectMenuFormat"><i class="fa fa-server"></i> Select Menu</button>
            <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
$('#btnMenu').click(function(){
    $(this).selectMenu({
        showField : 'name',
        keyField : 'id',
        initSelected : 1,
        //自定义菜单项目显示模板
        formatItem : function(row){
            var html = '<div class=""><div class="col-md-3">';
            html += '<img src="//repo.bfw.wiki/bfwrepo/image/5d65ea7d8bc8b.png?x-oss-process=image/auto-orient,1/resize,m_fill,w_100,h_100,/quality,q_90" width="64" height="64">';
            html += '</div>';
            html += '<div class="col-md-7">';
            html += row.name + row.name + '<br>' + row.desc;
            html += '</div></div>';
            return html;
        },
        data : selectMenuData
    });
});
]]>
</script>
        </div>


        <div class="row-fluid">
            <h2 class="page-header">4.1 鼠标右键打开菜单模式 <small>仅右键可打开</small></h2>
            <div class="row">
                <div class="col-md-6">
                    <p>常规模式菜单嵌入</p>
                    <div class="jumbotron" id="selectMenuRightClickBase">
                        <h3 class="text-center"><i class="fa fa-mouse-pointer"></i> Mouse right click this area</h3>
                    </div>
                    <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//html元素定义
<div class="jumbotron" id="selectMenuRightClickBase">
    <h3 class="text-center">
        <i class="fa fa-mouse-pointer"></i>
        Mouse right click this area
    </h3>
</div>
//javascript代码
$('#selectMenuRightClickBase').selectMenu({
    title : 'Regular menu',
    //常规菜单模式
    regular : true,
    //打开鼠标右键模式
    rightClick : true,
    data : baseMenuHeaderData
});
]]>
                    </script>
                </div>
                <div class="col-md-6">
                    <p>多功能模式菜单嵌入</p>
                    <div class="jumbotron" id="selectMenuRightClickAdv">
                        <h3 class="text-center"><i class="fa fa-mouse-pointer"></i> Mouse right click this area</h3>
                    </div>
                    <script type="syntaxhighlighter" class="brush:js">
<![CDATA[
//html元素定义
<div class="jumbotron" id="selectMenuR.........完整代码请登录后点击上方下载按钮下载查看

网友评论0