Passing mouse clicks through an overlaying element

前端 未结 4 695
别跟我提以往
别跟我提以往 2020-11-29 04:33

Is it possible to pass mouse clicks through an overlaying element:

相关标签:
4条回答
  • 2020-11-29 04:35

    You could try to retrieve the mouse coordinates in your click event and then retrieve an element by hiding your overlay, use document.elementFromPoint(x, y) and then redisplay the overlay.

    See this SO question for more info about elementFromPoint:

    How do I find the DOM node that is at a given (X,Y) position? (Hit test)

    0 讨论(0)
  • 2020-11-29 04:43

    I see you are using "rain.24.png" is the overlay animated? As in you are repositioning the images to simulate rain? If this is the case, then it might be best to stop/hide the animated on mousedown and then get the activate your function on the underlying elements using mouseup.

    If that isn't the case, then use Vincent's answer to get the element, then call the associated function or use trigger to simulate the click

    0 讨论(0)
  • 2020-11-29 04:47

    This can be solved using CSS:

    div { pointer-events:none; }
    

    Supported by IE 11+, Chrome, Firefox, Safari and Opera.

    More details: https://developer.mozilla.org/en-US/docs/CSS/pointer-events

    0 讨论(0)
  • 2020-11-29 04:58

    You could assign a mouse click event to the covering div, then iterate through all elements that you know might be underneath, inspecting their position, width, and height to see if that location of the mouse click was within their borders, and if it was, call their onclick event.

    To make the subset of possible elements smaller, you could give clickable elements that might be under the div, a special class.

    0 讨论(0)
提交回复
热议问题