开发者

Get item below another item in JavaScript

开发者 https://www.devze.com 2023-02-15 03:06 出处:网络
If you 开发者_如何学Gohave a document full of absolute positioned items and you set a document click handler (document.onclick = handler). Is it possible to get all objects that share the mouse positi

If you 开发者_如何学Gohave a document full of absolute positioned items and you set a document click handler (document.onclick = handler). Is it possible to get all objects that share the mouse position? i.e. two div boxes overlapped, not only the top one


Use the following algorithm:

  1. find out the x and y coordinates of mouse.
  2. Use document.elementFromPoint, add returned element to array.
  3. Hide that element using display:none
  4. Go to 2 until returned element is document.body
  5. Display all hidden elements.
0

精彩评论

暂无评论...
验证码 换一张
取 消