2017-08-21 08:51:13 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
2023-08-24 10:15:53 +08:00
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
|
|
|
|
<title>layer 弹层 - layui</title>
|
|
|
|
|
<link rel="stylesheet" href="../src/css/layui.css">
|
|
|
|
|
<style>
|
|
|
|
|
body{padding: 100px;}
|
|
|
|
|
#photos li{float: left; margin: 0 1px 1px;}
|
|
|
|
|
#photos img{max-height: 38px;}
|
|
|
|
|
</style>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
<div class="layui-btn-container">
|
2022-08-12 00:57:06 +08:00
|
|
|
|
<button class="layui-btn layui-btn-primary" lay-on="test">Alert</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test2">Confirm</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test3">Msg</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test5">Page</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test6">Iframe</button>
|
|
|
|
|
<button class="layui-btn" lay-on="testLoading">Loading</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test4">Tips</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test7">Prompt</button>
|
|
|
|
|
<button class="layui-btn" lay-on="test8">Tab</button>
|
2022-08-19 02:43:44 +08:00
|
|
|
|
<button class="layui-btn" lay-on="test9">Photo</button>
|
2022-08-12 00:57:06 +08:00
|
|
|
|
<button class="layui-btn" lay-on="testTime">自动关闭</button>
|
2023-08-28 11:02:18 +08:00
|
|
|
|
<a href="https://layui.dev/docs/2.8/layer/" target="_blank" class="layui-btn">更多例子</a>
|
2021-03-31 14:07:23 +08:00
|
|
|
|
</div>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2023-08-28 11:02:18 +08:00
|
|
|
|
<div id="test11111" style="display: none; padding: 16px;">
|
2021-05-08 12:30:00 +08:00
|
|
|
|
content 指向放置在页面的一段隐藏元素
|
2017-08-21 08:51:13 +08:00
|
|
|
|
</div>
|
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
<hr><br>
|
|
|
|
|
|
|
|
|
|
<div class="layui-list">
|
|
|
|
|
<ul class="layui-row" id="photos">
|
2022-08-19 02:43:44 +08:00
|
|
|
|
<li class="list"><img src="https://unpkg.com/outeres/demo/1.jpg" alt="123"></li>
|
2022-08-12 00:57:06 +08:00
|
|
|
|
<li class="list"><img src="https://unpkg.com/outeres/demo/2.jpg"></li>
|
2021-04-22 10:22:45 +08:00
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
2021-05-08 06:31:19 +08:00
|
|
|
|
<script>
|
|
|
|
|
var LAYUI_GLOBAL = {
|
2023-08-28 11:02:18 +08:00
|
|
|
|
// path: '../src/',
|
|
|
|
|
// layerPath: '../release/layer/src/'
|
2021-05-08 06:31:19 +08:00
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
<script src="../src/layui.js"></script>
|
2021-04-22 10:22:45 +08:00
|
|
|
|
|
|
|
|
|
<!-- layer 独立版调试 -->
|
|
|
|
|
<script src1="//cdn.staticfile.org/jquery/1.12.3/jquery.min.js"></script>
|
|
|
|
|
<script src1="../release/layer/src/layer.js"></script>
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
<script>
|
2021-04-22 10:22:45 +08:00
|
|
|
|
var runTest = function(run, $, layer){
|
|
|
|
|
if(!run) return;
|
|
|
|
|
|
|
|
|
|
var timer = setInterval(function(){
|
2021-05-08 06:31:19 +08:00
|
|
|
|
//location.reload();
|
2021-04-22 10:22:45 +08:00
|
|
|
|
}, 1000);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2021-05-08 06:31:19 +08:00
|
|
|
|
layer.alert(123);
|
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
$.ajax({
|
|
|
|
|
url: './all.html'
|
|
|
|
|
,beforeSend: function(){
|
2021-05-08 06:31:19 +08:00
|
|
|
|
//layer.ready(function(){
|
|
|
|
|
//layer.load();
|
|
|
|
|
//});
|
2021-04-22 10:22:45 +08:00
|
|
|
|
}
|
|
|
|
|
,success: function(){
|
2021-05-08 06:31:19 +08:00
|
|
|
|
return;
|
2021-04-22 10:22:45 +08:00
|
|
|
|
layer.closeAll('loading', function(){
|
|
|
|
|
setTimeout(function(){
|
|
|
|
|
if($('.layui-layer-loading').length){
|
|
|
|
|
console.error('layer close 异常');
|
|
|
|
|
clearInterval(timer);
|
|
|
|
|
}
|
|
|
|
|
}, 200);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
window.jQuery && runTest(1, window.jQuery, window.layer);
|
|
|
|
|
|
2022-05-27 07:28:25 +08:00
|
|
|
|
layui.use(['layer', 'util'], function(layer, util){
|
|
|
|
|
var $ = layui.jquery;
|
2022-08-12 00:57:06 +08:00
|
|
|
|
var util = layui.util;
|
2021-04-22 10:22:45 +08:00
|
|
|
|
//return
|
2021-03-31 14:07:23 +08:00
|
|
|
|
|
2022-08-12 00:57:06 +08:00
|
|
|
|
var index = layer.msg('Hello World');
|
2021-04-05 23:41:30 +08:00
|
|
|
|
//layer.close(index);
|
2021-04-22 10:22:45 +08:00
|
|
|
|
//runTest(1, $, layer);
|
|
|
|
|
|
2021-03-31 14:07:23 +08:00
|
|
|
|
|
2022-08-12 00:57:06 +08:00
|
|
|
|
// 触发事件
|
|
|
|
|
util.on('lay-on', {
|
2017-08-21 08:51:13 +08:00
|
|
|
|
test: function(){
|
2022-08-12 00:57:06 +08:00
|
|
|
|
var icon = -1;
|
|
|
|
|
(function changeIcon(){
|
|
|
|
|
var index = layer.alert('Hi,你好! 点击确认更换图标', {
|
|
|
|
|
icon: icon,
|
|
|
|
|
shadeClose: true,
|
|
|
|
|
title: icon === -1 ? 'Alert' : ('icon: '+ icon)
|
|
|
|
|
}, changeIcon);
|
|
|
|
|
if(icon++ > 6){
|
|
|
|
|
layer.close(index);
|
|
|
|
|
icon = -1;
|
2021-04-22 10:22:45 +08:00
|
|
|
|
}
|
2022-08-12 00:57:06 +08:00
|
|
|
|
}());
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}
|
|
|
|
|
,test2: function(){
|
2022-08-12 00:57:06 +08:00
|
|
|
|
layer.confirm('一个询问层的测试示例?', {
|
|
|
|
|
btn: ['确定','关闭'] //按钮
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}, function(){
|
2022-08-12 00:57:06 +08:00
|
|
|
|
layer.msg('第一个回调', {icon: 1});
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}, function(){
|
2022-08-12 00:57:06 +08:00
|
|
|
|
layer.msg('第二个回调', {
|
2017-08-21 08:51:13 +08:00
|
|
|
|
time: 20000, //20s后自动关闭
|
|
|
|
|
btn: ['明白了', '知道了']
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
,test3: function(){
|
2022-08-19 02:43:44 +08:00
|
|
|
|
!0 ? layer.msg('一个常用消息框')
|
2022-08-12 00:57:06 +08:00
|
|
|
|
: layer.msg('一个常用消息框',{closeBtn: 0,time: 0, icon: 16});
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}
|
|
|
|
|
,test4: function(){
|
|
|
|
|
layer.tips('Hi,我是一个小提示', this, {tips: 1});
|
|
|
|
|
}
|
|
|
|
|
,test5: function(){
|
2022-08-12 00:57:06 +08:00
|
|
|
|
layer.open({
|
2021-05-08 06:31:19 +08:00
|
|
|
|
title:'自定义页面层',
|
2017-08-21 08:51:13 +08:00
|
|
|
|
type: 1,
|
2022-08-12 00:57:06 +08:00
|
|
|
|
skin: 'layui-layer-border',
|
2021-03-31 14:07:23 +08:00
|
|
|
|
area: ['1000px', '580px'],
|
2021-05-08 12:30:00 +08:00
|
|
|
|
content: $('#test11111'),
|
2021-05-08 06:31:19 +08:00
|
|
|
|
maxmin: true,
|
2022-08-12 00:57:06 +08:00
|
|
|
|
shade: false,
|
2023-05-14 19:32:06 +08:00
|
|
|
|
minStack: false, // 最小化不堆叠在左下角
|
|
|
|
|
id: 'page-1', // 定义 ID,防止重复弹出
|
2021-05-08 06:31:19 +08:00
|
|
|
|
min: function(layero, index){
|
|
|
|
|
layer.msg('阻止了默认的最小化');
|
|
|
|
|
layer.style(index, {top: 'auto', bottom: 0});
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
,test6: function(){
|
|
|
|
|
layer.open({
|
2023-05-14 19:32:06 +08:00
|
|
|
|
type: 2,
|
|
|
|
|
content: 'https://www.aliyun.com/activity?userCode=ap0255is',
|
|
|
|
|
area: ['375px', '500px'],
|
|
|
|
|
id: 'iframe-1',
|
|
|
|
|
hideOnClose: true, // 关闭时是否隐藏弹层容器,下次打开时直接显示原来的弹层
|
|
|
|
|
maxmin: true
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-12 00:57:06 +08:00
|
|
|
|
,testLoading: function(){
|
2022-08-19 02:43:44 +08:00
|
|
|
|
layer.load(0, {
|
|
|
|
|
time: 5*1000
|
2022-08-12 00:57:06 +08:00
|
|
|
|
//content: '123'
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-08-21 08:51:13 +08:00
|
|
|
|
,test7: function(){
|
|
|
|
|
layer.prompt({title: '输入任何口令,并确认', formType: 1}, function(pass, index){
|
|
|
|
|
layer.close(index);
|
|
|
|
|
layer.prompt({title: '随便写点啥,并确认', formType: 2}, function(text, index){
|
|
|
|
|
layer.close(index);
|
2022-05-27 07:28:25 +08:00
|
|
|
|
layer.msg('演示完毕!您的口令:'+ util.escape(pass) +'<br>您最后写下了:'+ util.escape(text));
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
,test8: function(){
|
|
|
|
|
layer.tab({
|
|
|
|
|
area: ['600px', '300px'],
|
|
|
|
|
tab: [{
|
|
|
|
|
title: 'TAB1',
|
|
|
|
|
content: '内容1'
|
|
|
|
|
}, {
|
|
|
|
|
title: 'TAB2',
|
|
|
|
|
content: '内容2'
|
|
|
|
|
}, {
|
|
|
|
|
title: 'TAB3',
|
|
|
|
|
content: '内容3'
|
|
|
|
|
}]
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-19 02:43:44 +08:00
|
|
|
|
,test9: function(){
|
|
|
|
|
layer.photos({
|
|
|
|
|
photos: {
|
|
|
|
|
"data": [{
|
|
|
|
|
"src": "https://unpkg.com/outeres/demo/layer.png"
|
|
|
|
|
}]
|
|
|
|
|
},
|
|
|
|
|
hideFooter: true // 是否隐藏图片底部栏(v2.8.0 新增)
|
|
|
|
|
});
|
|
|
|
|
}
|
2022-08-12 00:57:06 +08:00
|
|
|
|
,testTime: function(){
|
|
|
|
|
layer.alert('你好么,体验者。<br>在标题栏显示自动关闭倒计秒数', {
|
|
|
|
|
time: 5*1000
|
|
|
|
|
,success: function(layero, index){
|
|
|
|
|
var timeNum = this.time/1000, setText = function(start){
|
|
|
|
|
layer.title((start ? timeNum : --timeNum) + ' 秒后关闭', index);
|
|
|
|
|
};
|
|
|
|
|
setText(!0);
|
|
|
|
|
this.timer = setInterval(setText, 1000);
|
|
|
|
|
if(timeNum <= 0) clearInterval(this.timer);
|
|
|
|
|
}
|
|
|
|
|
,end: function(){
|
|
|
|
|
clearInterval(this.timer);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2021-04-06 16:01:23 +08:00
|
|
|
|
|
2022-08-19 02:43:44 +08:00
|
|
|
|
// 相册层
|
2021-04-22 10:22:45 +08:00
|
|
|
|
layer.photos({
|
2023-08-24 10:15:53 +08:00
|
|
|
|
photos: '#photos', // $('#photos')
|
|
|
|
|
// toolbar: false,
|
|
|
|
|
// footer: false
|
2021-04-22 10:22:45 +08:00
|
|
|
|
});
|
2021-05-18 21:20:45 +08:00
|
|
|
|
|
2021-04-22 10:22:45 +08:00
|
|
|
|
//动态追加
|
2022-08-12 00:57:06 +08:00
|
|
|
|
$('#photos').append('<li class="list"><img src="https://unpkg.com/outeres/demo/3.jpg"></li>');
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|