You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
layui/examples/util.html

129 lines
3.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>util 组件 - layui</title>
<link rel="stylesheet" href="../src/css/layui.css">
<style>
body{padding: 50px;}
</style>
</head>
<body>
<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>
<button class="layui-btn" lay-active2="e4">事件4</button>
<hr>
<div id="test"></div>
<hr>
<div id="test1"></div>
<hr>
<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>
<script src="../src/layui.js"></script>
<script>
layui.use(['util', 'layer'], function(){
var $ = layui.$;
var util = layui.util;
var layer = layui.layer;
// 固定块
util.fixbar({
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 节点的目标元素选择器
// duration: 300, // top bar 等动画时长(毫秒)
on: { // 任意事件 -- v2.8.0 新增
mouseenter: function(type){
layer.tips(type, this, {
tips: 4,
fixed: true
});
},
mouseleave: function(type){
layer.closeAll('tips');
}
},
// 点击事件
click: function(type){
console.log(this, type);
// layer.msg(type);
}
});
//倒计时
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);
//处理属性 为 lay-active 的所有元素事件
util.event('lay-active', {
e1: function(othis){
alert(othis.html())
}
,e2: function(othis){
alert(othis.html())
}
,e3: function(othis){
alert(othis.html())
}
});
//测试是否重复绑定
util.event('lay-active', {
e1: function(othis){
alert(othis.html() + '新事件')
}
});
//测试绑定新事件
util.event('lay-active2', {
e4: function(othis){
alert(othis.html())
}
});
});
</script>
</body>
</html>