layui/examples/dropdown.html

262 lines
5.6 KiB
HTML
Raw Normal View History

2021-03-31 14:07:23 +08:00
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>下拉菜单 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css">
</head>
<body>
<div class="layui-container">
<div class="layui-btn-container" style="padding: 30px 0;">
<button class="layui-btn" id="demo1">
按钮下拉
<i class="layui-icon layui-icon-down layui-font-12"></i>
</button>
<button class="layui-btn layui-btn-primary" id="demo2">
2021-03-31 14:07:23 +08:00
按钮下拉
<i class="layui-icon layui-icon-down layui-font-12"></i>
</button>
2021-03-31 14:07:23 +08:00
</div>
2021-03-31 14:07:23 +08:00
<div class="layui-text">
<a href="javascript:;" id="demo3">文字下拉 <i class="layui-icon layui-icon-down"></i></a>
</div>
2021-03-31 14:07:23 +08:00
<div class="layui-bg-gray" style="margin-top: 30px; width: 100%; height: 300px; text-align: center;" id="demo20">
<span class="layui-font-gray" style="position: relative; top:50%;">鼠标右键菜单</span>
</div>
</div>
<script src="../src/layui.js"></script>
<script>
layui.use('dropdown', function(){
var dropdown = layui.dropdown;
dropdown.render({
elem: '#demo1'
2022-10-13 20:46:47 +08:00
,shade: [0.1, '#ddd']
2021-05-31 08:57:00 +08:00
//,align: 'right'
2021-03-31 14:07:23 +08:00
,data: [{
title: 'menu item 1'
2023-08-08 17:50:13 +08:00
,templet: '<i class="layui-icon layui-icon-light"></i> {{= d.title }} <span class="layui-badge-dot"></span>'
2021-03-31 14:07:23 +08:00
,id: ''
,href: ''
,type: '' //菜单类型支持normal/group/parent
},{
2023-08-08 17:50:13 +08:00
title: 'menu item <strong>2</strong>'
,templet: '<img src="https://unpkg.com/outeres@0.1.1/demo/avatar/0.png" style="width: 16px;"> {{- d.title }}'
2021-03-31 14:07:23 +08:00
,id: ''
,href: 'https://www.layui.com/'
,target: '_blank'
},{type: '-'},{},{
2023-08-08 17:50:13 +08:00
title: 'menu item 3 <hello>'
2021-03-31 14:07:23 +08:00
,id: ''
,type: 'group'
,child: [{
title: 'menu item 3-1'
,id: ''
},{
title: 'menu item 3-2'
,id: ''
,child: [{
title: 'menu item 3-2-1'
,id: ''
},{
title: 'menu item 3-2-2'
,id: ''
,type: 'group'
,child: [{
title: 'menu item 3-2-2-1'
,id: ''
},{
title: 'menu item 3-2-2-2'
,id: ''
}]
},{
title: 'menu item 3-2-3'
,id: ''
}]
},{
title: 'menu item 3-3'
,id: ''
,type: 'group'
,child: [{
title: 'menu item 3-3-1'
,id: ''
},{
title: 'menu item 3-3-2'
,id: ''
,child: [{
title: 'menu item 3-3-2-1'
,id: ''
},{
title: 'menu item 3-3-2-2'
,id: ''
},{
title: 'menu item 3-3-2-3'
,id: ''
}]
},{
title: 'menu item 3-3-3'
,id: ''
}]
}]
}
,{type: '-'}
,{
title: 'menu item 4'
,id: ''
},{
title: 'menu item 5'
,id: ''
,child: [{
title: 'menu item 5-1'
,id: ''
,child: [{
title: 'menu item 5-1-1'
,id: ''
},{
title: 'menu item 5-1-2'
,id: ''
},{
title: 'menu item 5-1-3'
,id: ''
}]
},{
title: 'menu item 5-2'
,id: ''
},{
title: 'menu item 5-3'
,id: ''
}]
},{type:'-'},{
title: 'menu item 6'
,id: ''
,type: 'group'
,isSpreadItem: false
,child: [{
title: 'menu item 6-1'
,id: ''
},{
title: 'menu item 6-2'
,id: ''
},{
title: 'menu item 6-3'
,id: ''
}]
}]
2021-03-31 14:07:23 +08:00
,id: 'demo1'
2022-08-26 23:26:17 +08:00
// 触发点击事件的元素范围 --- default: 仅子菜单触发点击事件(默认,可不填); all: 所有父子菜单均触发点击事件
,clickScope: 'all'
// 菜单被点击的事件
2021-03-31 14:07:23 +08:00
,click: function(obj){
console.log(obj);
}
});
2021-03-31 14:07:23 +08:00
var inst = dropdown.render({
elem: '#demo2'
2023-03-10 12:49:35 +08:00
// ,show: true
2021-03-31 14:07:23 +08:00
,data: [{
title: 'menu item 1'
,href: '#1'
2023-03-10 13:15:52 +08:00
,disabled: true
2021-03-31 14:07:23 +08:00
},{
2023-02-16 09:45:57 +08:00
title: 'menu item 2(点击不关闭)'
2021-03-31 14:07:23 +08:00
,href: '#2'
2023-02-16 09:45:57 +08:00
,id: 'bbb'
2021-03-31 14:07:23 +08:00
},{
title: 'menu item 3'
,href: '#3'
}]
2023-02-16 09:45:57 +08:00
,click: function(data, othis){
console.log(data);
if(data.id === 'bbb'){
return false;
}
2021-03-31 14:07:23 +08:00
}
2023-03-10 12:49:35 +08:00
,ready: function(){
console.log(arguments);
}
2021-03-31 14:07:23 +08:00
});
2021-03-31 14:07:23 +08:00
dropdown.render({
elem: '#demo3'
,content: '自定义内容 123 '
,style: 'background:#666;color:#fff;padding:15px;'
2021-05-31 08:57:00 +08:00
,align: 'center'
2021-03-31 14:07:23 +08:00
,trigger: 'hover'
});
2021-03-31 14:07:23 +08:00
//右键
dropdown.render({
elem: document//'#demo20' //也可绑定到 document从而重置整个右键
,trigger: 'contextmenu' //contextmenu
,isAllowSpread: false
//,style: 'width: 200px'
2023-08-15 21:55:31 +08:00
,customName: {
children: 'children'
}
2021-03-31 14:07:23 +08:00
,data: [{
title: 'menu item 1'
,id: '#1'
},{
title: 'menu item 2'
,id: 'reload'
},{type:'-'},{
title: 'menu item 3'
,id: '#3'
2023-08-15 21:55:31 +08:00
,children: [{
2021-03-31 14:07:23 +08:00
title: 'menu item 3-1'
,id: '#1'
},{
title: 'menu item 3-2'
,id: '#2'
},{
title: 'menu item 3-3'
,id: '#3'
}]
},{type:'-'},{
title: 'menu item 4'
,id: ''
},{
title: 'menu item 5'
,id: '#1'
},{
title: 'menu item 6'
,id: '#1'
}]
,click: function(obj, othis){
if(obj.id === 'reload'){
location.reload();
}
}
});
2021-03-31 14:07:23 +08:00
return;
2021-03-31 14:07:23 +08:00
dropdown.render({
elem: document
,content: '123'
});
});
</script>
</body>
</html>