一套开源的 Web UI 组件库。采用自身极简的模块化规范,并遵循原生 HTML/CSS/JS 的开发模式,极易上手,开箱即用。非常适合网页界面的快速构建。
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.

129 lines
3.6 KiB

7 years ago
<!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>
7 years ago
<link rel="stylesheet" href="../src/css/layui.css">
<style>
body{padding: 50px;}
</style>
</head>
<body>
6 years ago
<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>
5 years ago
<button class="layui-btn" lay-active2="e4">事件4</button>
6 years ago
<hr>
7 years ago
<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>
7 years ago
<script src="../src/layui.js"></script>
<script>
layui.use(['util', 'layer'], function(){
var $ = layui.$;
var util = layui.util;
var layer = layui.layer;
7 years ago
// 固定块
7 years ago
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){
7 years ago
console.log(this, type);
// layer.msg(type);
7 years ago
}
});
//倒计时
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);
6 years ago
//处理属性 为 lay-active 的所有元素事件
util.event('lay-active', {
5 years ago
e1: function(othis){
alert(othis.html())
}
,e2: function(othis){
alert(othis.html())
6 years ago
}
5 years ago
,e3: function(othis){
alert(othis.html())
}
});
//测试是否重复绑定
util.event('lay-active', {
e1: function(othis){
alert(othis.html() + '新事件')
6 years ago
}
5 years ago
});
//测试绑定新事件
util.event('lay-active2', {
e4: function(othis){
alert(othis.html())
6 years ago
}
});
7 years ago
});
</script>
</body>
</html>