【问题标题】:Hover/mouse actions are firing on cut-off border of SVG with border-radius [duplicate]悬停/鼠标动作在具有边界半径的 SVG 的截止边界上触发 [重复]
【发布时间】:2020-12-20 05:40:01
【问题描述】:

据我所知,边框半径应该会阻止鼠标事件发生在被移除的边框上。

我有一个循环的 svg/div,它仍然在元素之外触发动作和 :hover 事件。主项目中容器的 onClick 事件也会发生这种情况。

Overflow:hidden 给了我想要的结果,但感觉它并不能解决问题。它还隐藏了我想要的盒子阴影。

我主要只是想知道为什么会发生这种情况以及问题的解决方案,而不是解决方法。

https://jsfiddle.net/30m8dj5c/1/

svg {
      background-color:blue;
    /* position: relative; */
    /* bottom: 25px; */
    border-radius: 1000px;
    height: 100%;
    width: auto;
    /* box-shadow: ; */
    
}

【问题讨论】:

  • 这是一个影响 Chrome(以及所有 webkit 浏览器)的已知问题,您可以阅读更多关于它的信息 on this other question。这个问题基本上是那个问题的重复。阴影的可能解决方案是将 overflow:hiddenbox-shadow 添加到包含 SVG 的 div 中。

标签: html css reactjs


【解决方案1】:

我更改了一些hover 效果。

body {
  background-color: lightblue;
}
.carosel-caret-container {
    z-index: 1;
    position: absolute;
    transform: translateY(0);
    height: 50%;
    border-radius: 100%;
}
svg {
    background-color:blue;
    border-radius: 1000px;
    border: none;
    height: 100%;
    width: auto;
}
.circle, .caret {
    transition: all .1s ease-in-out;
    cursor: pointer;
}
.circle {
    fill: black;
    fill-opacity: 0.75
}

.caret {
    fill: white;
    fill-opacity: 1;
}
svg .circle:hover {
    fill: white;
    fill-opacity: 0.8;
}

svg .caret:hover {
    fill: black;
    fill-opacity: 0.85;
}
svg:hover{
  box-shadow: 0 0 12px -4px rgba(0, 0, 0, 0.6);
}

【讨论】:

  • 这确实做了我想要的,我可以通过道具将我需要的 onclick 函数传递给圆圈。但这并没有解决我不知道为什么用边界半径删除的边界仍然是 svg 的一部分的问题。背景颜色甚至被切断,所以没有意义。不过,感谢您的解决方法!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-04-30
  • 2021-06-21
相关资源
最近更新 更多