Getting DIV id based on x & y position

后端 未结 9 843
渐次进展
渐次进展 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:39

    One option is to build an array of "div-dimension" objects. (Not to be confused with the divs themselves... IE7 perf is frustrating when you read dimensions off of object.)

    These objects consist of a pointer to the div, their dimensions (four points... say top, left, bottom, and right), and possibly a dirty bit. (Dirty bit is only really needed if the sizes change.

    You could then iterate through the array and check dimensions. It requires O(n) to do that on each mouse move. You might be able to do slightly better with a binary search style approach... maybe.

    If you do a binary search style approach, one way is to store 4 arrays. Each with a single point of the dimension, and then binary search on all four. O(4logn) = O(logn).

    I'm not saying I recommend any of these, but they MIGHT work.

提交回复
热议问题