取色器

chrome97支持了取色器功能,支持用户点击从屏幕取色

支持检测

1
2
3
if(!window.EyeDropper){
console.error('不支持滴管api')
}

使用实例

1
2
3
4
5
6
7
8
9
10
let eye
if (window.EyeDropper) {
eye = new EyeDropper()
eye.open().then(
(colorResult) =>{ console.log(colorResult.sRGBHex)}
).catch(e=>{
// 点击esc退出选取时触发
console.error('用户取消选择颜色')
})
}

在线运行