一套开源的 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.

121 lines
2.6 KiB

6 years ago
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
6 years ago
<title>颜色选择器 - layui</title>
6 years ago
<link rel="stylesheet" href="../src/css/layui.css">
<style>
body{padding:20px;}
6 years ago
.test-box{margin-bottom: 50px;}
6 years ago
</style>
</head>
<body>
<div class="layui-container">
6 years ago
<div class="test-box">
<div class="layui-inline">
<input class="layui-input" id="LAY-test1">
6 years ago
</div>
6 years ago
<div id="test1"></div>
</div>
<div class="test-box">
<div id="test2"></div>
</div>
<div class="test-box">
<div id="test3"></div>
</div>
<div class="test-box">
<div id="test4"></div>
</div>
<div class="test-box">
<div id="test5"></div>
</div>
<div class="test-box">
<div id="test6"></div>
6 years ago
</div>
2 years ago
<div class="test-box">
<div class="test-more"></div>
<div class="test-more"></div>
<div class="test-more"></div>
</div>
6 years ago
</div>
<script src="../src/layui.js"></script>
<script>
6 years ago
layui.use(['colorpicker', 'layer'], function(){
6 years ago
var colorpicker = layui.colorpicker;
colorpicker.render({
elem: '#test1'
6 years ago
//,predefine: true //开启预定义颜色
//,colors: ['#F00','#0F0','#00F','rgb(255, 69, 0)','rgba(255, 69, 0, 0.5)']
6 years ago
,change: function(color){
6 years ago
document.body.style.backgroundColor = color;
}
,done: function(color){
layui.$('#LAY-test1').val(color);
document.body.style.backgroundColor = color;
6 years ago
}
});
6 years ago
6 years ago
colorpicker.render({
elem: '#test2'
6 years ago
,color: 'rgba(218, 121, 157, 1)' //设置默认色
6 years ago
,predefine: true
,alpha: true //开启透明度
,format: 'rgb'
,change: function(color){
console.log(color)
}
});
6 years ago
6 years ago
colorpicker.render({
6 years ago
elem: '#test3'
6 years ago
,color: 'rgba(0,0,0)'
//,alpha: true
//,format: 'rgb' //设置输入显示格式为rgb
6 years ago
});
6 years ago
6 years ago
colorpicker.render({
elem: '#test4'
6 years ago
,color: '#06eeb8'
6 years ago
,predefine: true //开启预定义色
,format: 'rgb'
});
6 years ago
6 years ago
colorpicker.render({
elem: '#test5'
6 years ago
,color: '#ffd900'
6 years ago
,predefine: true
6 years ago
,size: 'lg'
6 years ago
});
6 years ago
6 years ago
colorpicker.render({
elem: '#test6'
6 years ago
,color: '#F00'
6 years ago
,predefine: true
6 years ago
,colors: ['#F00','#0F0','#00F','rgb(255, 69, 0)','rgba(255, 69, 0, 0.5)']
6 years ago
,size: 'xs'
});
2 years ago
// 同时绑定多个
colorpicker.render({
elem: '.test-more',
done: function(color){
console.log(this.elem, color);
}
});
6 years ago
})
</script>
</body>
</html>