简体   繁体   English

javascript禁用边框半径单击事件

[英]javascript disable border-radius click event

I want to disable the click event for border fields. 我想禁用边框字段的click事件。 Why are borders clickable and how can I fix it? 为什么边框是可点击的,我该如何解决?

.circle {
    border-radius: 100px;
}

span {
    display: block;
    background: #000;
    width: 200px;
    height: 400px;
    border-radius: 100px;
}

JS Fiddle Demo JS小提琴演示

Thanks. 谢谢。

You can solve this undesired effect using CSS, because the user is not clicking in the span element, but in a (that doesn't have border-radius ). 您可以解决使用CSS这种不良影响,因为用户没有在点击span元素,但在a (即没有border-radius )。

To solve this, just remove the span element and it's styles, and style the a element instead: 为了解决这个问题,只需删除span元素及其样式,然后为a元素设置样式:

a {
    display:block;
    background:#000;
    width:200px;
    height:400px;
    border-radius:100px;
}

Working demo . 工作演示

Demonstration of how the a area can affect your code . 该怎么示范a区域可能会影响你的代码

This is not possible, at least without a lot of very complicated maths to determine whether the click was inside the element or beyond the curves. 这是不可能的,至少没有很多非常复杂的数学来确定单击是在元素内部还是在曲线之外。

Remember elements have box models; 记住元素有盒子模型。 so even if you curve them, they are still viewed as boxes by the browser and represented as such in the DOM. 因此,即使您将它们弯曲,它们仍会被浏览器视为方框,并在DOM中表示为方框。 If they weren't, you'd have nearby elements seeping into the space vacated by the border radius, which doesn't happen. 如果不是,则周围的元素会渗入边界半径所腾出的空间中,这不会发生。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM