layui/examples/colorpicker.html

128 lines
2.9 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>
2022-07-29 10:46:56 +08:00
<div class="test-box">
2022-07-29 10:47:58 +08:00
<div class="test-more" lay-options="{color: '#FF0000'}"></div>
<div class="test-more" lay-options="{color: '#008000'}"></div>
<div class="test-more" lay-options="{color: '#0000FF'}"></div>
2022-07-29 10:46:56 +08:00
</div>
2018-08-18 20:46:14 +08:00
</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){
2022-08-04 15:17:18 +08:00
this.done(color);
2018-08-28 15:43:16 +08:00
}
,done: function(color){
layui.$('#LAY-test1').val(color);
document.body.style.backgroundColor = color;
2018-08-18 20:46:14 +08:00
}
2022-08-04 02:46:41 +08:00
,cancel: function(color){
2022-08-04 15:17:18 +08:00
this.done(color);
2022-08-04 02:46:41 +08:00
console.log('cancel', color);
}
,close: function(color){
console.log('close', 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'
2023-04-22 16:13:52 +08:00
,color: '#000'
2018-08-28 15:43:16 +08:00
//,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'
});
2022-07-29 10:46:56 +08:00
// 同时绑定多个
colorpicker.render({
elem: '.test-more',
done: function(color){
console.log(this.elem, color);
}
});
2018-08-18 20:46:14 +08:00
})
</script>
</body>
</html>