Click through div with an alpha channel

假如想象 提交于 2019-12-12 07:54:47

问题


I'm trying to replicate twitter's "fade out" layer at the bottom of the feed widget (on their main page at twitter.com).

The only way I could come up with that didn't use html5 was place an absolute positioned div above the feed div, and give it an alpha channeled png with a white-to-transparent gradient above it. This was easy to achieve.

Only problem now is that the divs that appear below the transparent layers are not clickable. Any idea about how to make the divs clickable? Maybe you have another method to replicate this effect altogether?

Thanks!


回答1:


This article describes one method of capturing the onclick event, and handling it by momentarily hiding the overlay, refiring the click, then unhiding it again. The hiding shouldn't be visible to the end user.

Forwarding Mouse Events Through Layers :

  1. The textarea (my masking element) that is positioned over the grid receives mouseover, mousemove, mousedown , mouseup and other events.
  2. The top masking layer is hidden for a moment, so we can figure out what element is below the mask at the event location.
  3. The event is re-fired - this is where the W3 DOM Event model and the simpler Microsoft equivalent come into play.
  4. Start the process again - ready for the next event.

EDIT: I think what Twitter does is actually much simpler. There's a CSS property borrowed from SVG that a bunch of browsers have implemented.

.overlay { pointer-events: none; }

This is currently supported in Firefox 3.6+, Safari 4 and Google Chrome - so if you're happy for it to only work on these browsers then this is a much simpler option, with the added advantage that it works for hover events too, not just click events.




回答2:


For IE, just set the bottom div or layer to use a negative index, like this:

{pointer-events: none; z-index: -100}


来源:https://stackoverflow.com/questions/3793204/click-through-div-with-an-alpha-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!