我想给htmlconst html = document.documentElement const mouseenter = async (img,i) => { console.log(img); hoverIndex.value = i const res = await colorThief.getPalette(img, 3) console.log('res', res); const [c1, c2, c3] = res.map(c => `rgb(${c[0]}, ${c[1]}, ${c[2]})`) console.log(c1, c2, c3); }设置渐变色c1,c2,c3
时间: 2024-03-07 10:49:19 浏览: 100
document.documentElement && document.documentElement.scrollTop
你可以在 `mouseenter` 事件中给 `html` 元素设置渐变色,代码如下:
```javascript
const html = document.documentElement;
const mouseenter = async (img, i) => {
console.log(img);
hoverIndex.value = i;
const res = await colorThief.getPalette(img, 3);
console.log('res', res);
const [c1, c2, c3] = res.map(c => `rgb(${c[0]}, ${c[1]}, ${c[2]})`);
console.log(c1, c2, c3);
// 设置渐变色
html.style.background = `linear-gradient(to bottom right, ${c1}, ${c2}, ${c3})`;
}
```
这样,当鼠标移动到图片上时,就会获取到颜色值,并将 `html` 元素的背景设置为渐变色。
阅读全文