CSS:隐藏对象可点击?(CSS: Is a hidden object clickable?)

编程入门 行业动态 更新时间:2024-10-28 00:24:02
CSS:隐藏对象可点击?(CSS: Is a hidden object clickable?)

如果HTML元素的风格的visibility属性设置为hidden ,是否仍然可以点击?

当display属性设置为none ,该元素不是DOM树的一部分,因此这不是问题。 但我想知道一个hidden元素是否仍然响应鼠标事件。

If the visibility property of the style of an HTML element is set to hidden, is it still clickable?

When the display property is set to none, the element is not even part of the DOM tree, so that is not a problem. But I was wondering if a hidden element still responds to mouse events.

最满意答案

使用display: none它仍然是DOM的一部分。 它只是没有在视口中渲染。

对于具有visibility: hidden元素的点击visibility: hidden ,事件不会被触发。

jsFiddle 。

$('div').click(function() {
    alert('Hello')
}); 
  
div {
    width: 100%;
    height: 100%;
    visibility: hidden; 
} 
  
<div>abc</div> 
  
 

With display: none it is still part of the DOM. It just isn't rendered in the viewport.

As for clicks on elements with visibility: hidden, the events are not fired.

jsFiddle.

$('div').click(function() {
    alert('Hello')
}); 
  
div {
    width: 100%;
    height: 100%;
    visibility: hidden; 
} 
  
<div>abc</div> 
  
 

更多推荐

本文发布于:2023-07-15 05:31:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1110701.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   CSS   hidden   clickable   object

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!