Getting DIV id based on x & y position

后端 未结 9 833
渐次进展
渐次进展 2020-12-06 11:52

The problem I\'m trying to solve is \"What\'s at this position?\"

It\'s fairly trivial to get the x/y position (offset) of a DIV, but what about the reverse? How do

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 12:28

    If all you have is the X and Y position, (and you can't track mouse movement like you mentioned) then you will have to traverse the DOM, looping through every DIV. For each DIV you will need to compare its X and Y coordinates against those you have. This is an expensive operation, but it is the only way. I suggest you might be better off rethinking your problem instead of coming up with a solution for it.

提交回复
热议问题