find elements that are stacked under (visually) an element in jquery

前端 未结 4 2082
小鲜肉
小鲜肉 2020-11-29 09:37

if i have 2 divs (z index is not assigned), one layered over the over, can i use the reference to the top div to find which div is below it?

as far as the DOM struct

4条回答
  •  旧时难觅i
    2020-11-29 10:16

    Check if box1 is sharing the same position as a certain spot on the page.


    And only because I'm a little bored, I made this awesome-er

    http://jsfiddle.net/hunter/PBAb6/

    function GetAllElementsAt(x, y) {
        var $elements = $("body *").map(function() {
            var $this = $(this);
            var offset = $this.offset();
            var l = offset.left;
            var t = offset.top;
            var h = $this.height();
            var w = $this.width();
    
            var maxx = l + w;
            var maxy = t + h;
    
            return (y <= maxy && y >= t) && (x <= maxx && x >= l) ? $this : null;
        });
    
        return $elements;
    }
    

提交回复
热议问题