鼠标悬停时反转文本颜色
这个GIF演示了所需的效果:
[文本变成白色的GIF鼠标悬停]
可以使用 CSS 和 JS 创建此效果。一种方法涉及操纵重复文本图层的剪辑路径以显示悬停时的反转颜色。
h1 {
color: #000;
display: inline-block;
margin: 50px;
text-align: center;
position: relative;
}
h1:before {
position: absolute;
content: attr(data-text);
color: #fff;
background: #000;
clip-path: circle(20px at var(--x, -100%) var(--y, -100%));
}
document.body.onmousemove = function(e) {
// Adjust the cursor position
c.style.left = e.clientX 'px';
c.style.top = e.clientY 'px';
// Adjust the clip-path
h.style.setProperty('--x', (e.clientX - p.top) 'px');
h.style.setProperty('--y', (e.clientY - p.left) 'px');
}
当鼠标移动时,脚本会调整剪辑路径以显示更多反转文本,从而创建悬停效果。
免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。
Copyright© 2022 湘ICP备2022001581号-3