扫码关注官方订阅号
如何仅更改鼠标所在位置的文本颜色而不是所有文本的颜色?像这样
我希望您可以看到的圆圈跟随鼠标移动,并且在悬停时文本仅显示悬停中的字母部分的边框
我需要有关我需要使用哪个库或函数的建议?
const fx = document.querySelector(".fx"); document.addEventListener("pointermove", e => { fx.style.top = e.clientY + "px"; fx.style.left = e.clientX + "px"; fx.querySelector("h1").style.transform = `translate(${(e.clientX - fx.getBoundingClientRect().width / 2) * -1}px, ${(e.clientY - fx.getBoundingClientRect().height / 2) * -1}px)`; })
* { box-sizing: border-box; padding: 0; margin: 0; } .container { position: relative; } .container h1 { font-size: 10rem; color: red; } .container .fx { width: 100px; height: 100px; outline: 1px solid blue; border-radius: 50%; position: absolute; top: -100px; left: -100px; overflow: hidden; transform: translate(-50%, -50%); background-color: white; } .container .fx h1 { font-size: 10rem; color: transparent; -webkit-text-stroke: 2px green; cursor: default; position: relative; }
abc abc
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部