You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何实现可点击链接仅在clip-path裁剪区域内显示并使用offsetX值

以下是可直接运行的修复实现,调整点如下:

  • 补全了所有容器的基础宽高、定位样式,保证视觉层正常渲染
  • 修正了clip-path的语法错误,补全Y轴坐标和闭合括号,同时保留了你需要的offsetX参数
  • clip-path原生特性会自动屏蔽裁剪区域外的元素交互,仅区域内的链接可以正常点击,完全匹配需求
<style>
.wrap {
  width: 800px;
  height: 600px;
  position: relative;
  margin: 0 auto;
  cursor: pointer;
}
.mouse {
  background-color: aqua;
  position: absolute;
  inset: 0;
}
              
.img {
  background-color: black;
  position: absolute;
  inset: 0;
}

#anchor {
  text-align: center;
  margin-top: 2em;
  font-size: 24px;
}
</style>
            
<div class="wrap">
  <div class="img"></div>
  <div class="mouse">
    <p id="anchor"></p>
  </div>    
</div>
             
<script>
let main = document.querySelector('.wrap');
let mouse = document.querySelector('.mouse');
let text = "Text link";
let result = text.link("#");
document.getElementById("anchor").innerHTML = result;
 
main.addEventListener('mousemove', (e) => {
  mouse.style.clipPath = `circle(15em at ${e.offsetX}px ${e.offsetY}px)`; 
});
</script>

内容的提问来源于stack exchange,提问作者LDX

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 21:45:06