2017-08-21 08:51:13 +08:00
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
<html>
|
|
|
|
|
<head>
|
|
|
|
|
<meta charset="utf-8">
|
|
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
|
2022-08-29 12:30:46 +08:00
|
|
|
|
<title>util 组件 - layui</title>
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="../src/css/layui.css">
|
|
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
body{padding: 50px;}
|
|
|
|
|
</style>
|
|
|
|
|
</head>
|
|
|
|
|
<body>
|
|
|
|
|
|
2019-05-31 14:36:29 +08:00
|
|
|
|
<button class="layui-btn" lay-active="e1">事件1</button>
|
|
|
|
|
<button class="layui-btn" lay-active="e2">事件2</button>
|
|
|
|
|
<button class="layui-btn" lay-active="e3">事件3</button>
|
|
|
|
|
|
2020-01-15 06:30:00 +08:00
|
|
|
|
<button class="layui-btn" lay-active2="e4">事件4</button>
|
|
|
|
|
|
2019-05-31 14:36:29 +08:00
|
|
|
|
<hr>
|
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
<div id="test"></div>
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
|
|
|
|
<div id="test1"></div>
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
2023-08-06 22:27:30 +08:00
|
|
|
|
请编辑格式:
|
|
|
|
|
<div class="layui-inline">
|
|
|
|
|
<input type="text" value="yyyy-MM-dd HH:mm:ss" class="layui-input" id="test2"/>
|
|
|
|
|
</div>
|
|
|
|
|
<span class="layui-word-aux" id="test3"></span>
|
|
|
|
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
2022-09-05 01:17:59 +08:00
|
|
|
|
<div id="target-test" style1="position: relative; height: 300px; overflow: auto;">
|
|
|
|
|
1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>1<br>
|
|
|
|
|
</div>
|
2022-08-29 12:30:46 +08:00
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
<script src="../src/layui.js"></script>
|
|
|
|
|
<script>
|
2022-08-29 12:30:46 +08:00
|
|
|
|
layui.use(['util', 'layer'], function(){
|
|
|
|
|
var $ = layui.$;
|
|
|
|
|
var util = layui.util;
|
|
|
|
|
var layer = layui.layer;
|
2017-08-21 08:51:13 +08:00
|
|
|
|
|
2022-08-29 12:30:46 +08:00
|
|
|
|
// 固定块
|
2017-08-21 08:51:13 +08:00
|
|
|
|
util.fixbar({
|
2022-08-29 12:30:46 +08:00
|
|
|
|
bars: [{ // 定义可显示的 bar 列表信息 -- v2.8.0 新增
|
|
|
|
|
type: 'share',
|
|
|
|
|
icon: 'layui-icon-share'
|
|
|
|
|
}, {
|
|
|
|
|
type: 'help',
|
|
|
|
|
icon: 'layui-icon-help'
|
|
|
|
|
}, {
|
|
|
|
|
type: 'cart',
|
|
|
|
|
icon: 'layui-icon-cart',
|
|
|
|
|
style: 'background-color: #FF5722;'
|
|
|
|
|
}, {
|
|
|
|
|
type: 'groups',
|
|
|
|
|
content: '群',
|
|
|
|
|
style: 'font-size: 21px;'
|
|
|
|
|
}],
|
|
|
|
|
// bar1: true,
|
|
|
|
|
// bar2: true,
|
|
|
|
|
// default: false, 是否显示默认的 bar 列表 -- v2.8.0 新增
|
|
|
|
|
// bgcolor: '#393D52', // bar 的默认背景色
|
|
|
|
|
// css: {right: 100, bottom: 100},
|
|
|
|
|
// target: '#target-test', // 插入 fixbar 节点的目标元素选择器
|
2022-09-05 01:17:59 +08:00
|
|
|
|
// duration: 300, // top bar 等动画时长(毫秒)
|
2022-08-29 12:30:46 +08:00
|
|
|
|
on: { // 任意事件 -- v2.8.0 新增
|
|
|
|
|
mouseenter: function(type){
|
|
|
|
|
layer.tips(type, this, {
|
|
|
|
|
tips: 4,
|
|
|
|
|
fixed: true
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
mouseleave: function(type){
|
|
|
|
|
layer.closeAll('tips');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// 点击事件
|
|
|
|
|
click: function(type){
|
2017-08-21 08:51:13 +08:00
|
|
|
|
console.log(this, type);
|
2022-08-29 12:30:46 +08:00
|
|
|
|
// layer.msg(type);
|
2017-08-21 08:51:13 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//倒计时
|
|
|
|
|
var endTime = new Date(2099,1,1).getTime() //假设为结束日期
|
|
|
|
|
,serverTime = new Date().getTime(); //假设为当前服务器时间,这里采用的是本地时间,实际使用一般是取服务端的
|
|
|
|
|
|
|
|
|
|
util.countdown(endTime, serverTime, function(date, serverTime, timer){
|
|
|
|
|
var str = date[0] + '天' + date[1] + '时' + date[2] + '分' + date[3] + '秒';
|
|
|
|
|
$('#test').html('距离2099年1月1日还有:'+ str);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//某个时间在当前时间的多久前
|
|
|
|
|
var str = util.timeAgo(new Date(2017,7,15,2,58,0));
|
|
|
|
|
$('#test1').html('示例写于:'+ str);
|
2019-05-31 14:36:29 +08:00
|
|
|
|
|
|
|
|
|
//处理属性 为 lay-active 的所有元素事件
|
|
|
|
|
util.event('lay-active', {
|
2020-01-15 06:30:00 +08:00
|
|
|
|
e1: function(othis){
|
|
|
|
|
alert(othis.html())
|
|
|
|
|
}
|
|
|
|
|
,e2: function(othis){
|
|
|
|
|
alert(othis.html())
|
2019-05-31 14:36:29 +08:00
|
|
|
|
}
|
2020-01-15 06:30:00 +08:00
|
|
|
|
,e3: function(othis){
|
|
|
|
|
alert(othis.html())
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//测试是否重复绑定
|
|
|
|
|
util.event('lay-active', {
|
|
|
|
|
e1: function(othis){
|
|
|
|
|
alert(othis.html() + '新事件')
|
2019-05-31 14:36:29 +08:00
|
|
|
|
}
|
2020-01-15 06:30:00 +08:00
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
//测试绑定新事件
|
|
|
|
|
util.event('lay-active2', {
|
|
|
|
|
e4: function(othis){
|
|
|
|
|
alert(othis.html())
|
2019-05-31 14:36:29 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
2023-08-06 22:27:30 +08:00
|
|
|
|
|
|
|
|
|
// 转换日期格式
|
|
|
|
|
var timer = null
|
|
|
|
|
var toDateString = function (format) {
|
2023-08-06 23:18:07 +08:00
|
|
|
|
var dateString = util.toDateString(new Date(), format);
|
2023-08-06 22:27:30 +08:00
|
|
|
|
$('#test3').html(dateString)
|
|
|
|
|
}
|
|
|
|
|
timer = setInterval(() => {
|
|
|
|
|
toDateString($('#test2').val())
|
|
|
|
|
}, 50)
|
2019-05-31 14:36:29 +08:00
|
|
|
|
|
2017-08-21 08:51:13 +08:00
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
</body>
|
|
|
|
|
</html>
|