且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

HTML“覆盖”它允许点击通过到它后面的元素

更新时间:2023-08-24 17:07:04

将元素的高度设置为零,但溢出:visible;将此与指针事件组合:none;似乎涵盖了所有的基础。

  .overlay {
height:0px;
overflow:visible;
pointer-events:none;
background:none!important;
}


I'm trying to overlay a element on top of a webpage (to draw arbitrary graphics), and I've come to the point where I can stack it inside of a element on top of everything, but this prevents the user from clicking on any links/buttons/etc. Is there a way to have its content float on top of everything (it's semi-transparent, so you can still see what is behind) and have the user interact with the layer below it?

I've found a lot of information on the DOM event model, but none of it addresses the problem where the buttons and other "native" controls never seem to get the clicks in the first place.

Thanks for any help!

A silly hack I did was to set the height of the element to zero but overflow:visible; combining this with pointer-events:none; seems to cover all the bases.

.overlay {
    height:0px;
    overflow:visible;
    pointer-events:none;
    background:none !important;
}