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/colorpicker.html

128 lines
2.9 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" lay-options="{color: '#FF0000'}"></div>
<div class="test-more" lay-options="{color: '#008000'}"></div>
<div class="test-more" lay-options="{color: '#0000FF'}"></div>
2 years ago
</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){
this.done(color);
6 years ago
}
,done: function(color){
layui.$('#LAY-test1').val(color);
document.body.style.backgroundColor = color;
6 years ago
}
,cancel: function(color){
this.done(color);
console.log('cancel', color);
}
,close: function(color){
console.log('close', 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'
,color: '#000'
6 years ago
//,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>