layui-js/examples/colorpicker.html

107 lines
2.3 KiB
HTML
Raw Normal View History

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