<button id="start-button">Open the eyedropper</button>
<span id="result"></span>
document.getElementById('start-button').addEventListener('click', () => {
const resultElement = document.getElementById('result');
if (!window.EyeDropper) {
resultElement.textContent = 'Your browser does not support the EyeDropper API';
return;
}
const eyeDropper = new EyeDropper();
eyeDropper.open().then(result => {
resultElement.textContent = result.sRGBHex;
resultElement.style.backgroundColor = result.sRGBHex;
}).catch(e => {
resultElement.textContent = e;
});
});
目前还处于实验阶段,兼容性不强