colorpicker.js颜色选择器的使用

下载链接
demo

初始化

<body>
	<div class="abc">
		<div class="picker" id="color-picker">
		</div>
	</div>
</body>
<script>
	new Colorpicker({
		el: "color-picker",
		color: "#000fff", // 初始色
		change: function (elem, hex) {
			elem.style.backgroundColor = hex;
			console.log(elem,hex);// dom元素-elem;十六进制颜色-hex
		}
	})
</script>

显示效果

image

其他

js源代码里

this.util.css(div, {
			"position": "absolute",
			"z-index": 2,// 这个设大点,动态生成的div会显示在最上边(有的页面本身比2大,会被遮挡)
			"display": 'none', // 初始化完成后是否直接出现弹窗
			"left": left + "px",
			"top": top + this.bindElem.offsetHeight + "px"
		});
posted @ 2022-06-20 17:33  风紧·扯呼  阅读(1482)  评论(0)    收藏  举报