如何在鼠标位置获取所有元素

How to get all elements at mouse position?

本文关键字:元素 获取 位置 鼠标      更新时间:2024-04-04

我在同一位置上有很多元素,我想在后面的每个元素上监听悬停事件,即使它们在其他元素后面,有办法做到这一点吗
(它们没有层次关系,有时是圆形、多边形等,因此检查边界矩形是不可行的)

http://jsfiddle.net/4NdNS/4/

$circles.on("mouseover",function(){console.log(this);});

这就是解决方案:

FIDDLE

html:

<div id=response></div>
<svg id="mycircle Area">
    <circle  id="C1" fill="none" r="20" stroke="black" stroke-width="4" cx="100" cy="100"></circle>
    <circle fill="none" r="20" stroke="black" stroke-width="4" cx="100" cy="100"></circle>
    <circle fill="none" r="20" stroke="black" stroke-width="4" cx="100" cy="100"></circle>
</svg>

jq:

$('circle').on("mousedown",function(e){
   $("#response").append($(e).attr('id')+' ');
    e.preventDefault();
});

css:

circle{
    pointer-events: all;
}

这是您编辑过的小提琴