我在同一位置有许多元素,我想监听后面每个元素的悬停事件,即使它们位于其他元素后面,有什么办法可以做到这一点吗?
(它们没有层次关系,有时它们是圆形、多边形等,因此检查边界矩形是不行的)
$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;
}
<小时/>
这是您编辑的fiddle
关于javascript - 如何获取鼠标所在位置的所有元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20432393/