If we are talking about 2 superposed DOM elements yes, it's possible. Can't really tell out of the structure of your HTML because it's not there but keep in mind that the event will bubble through its parents even if the element is not in being moused over.
$('#container').on('mouseover', function(){
$('#results1').html('Inside green square');
$('#results3').html('Last caller: green');
});
$('#child').on('mouseover', function(){
$('#results2').html('Inside blue square');
$('#results3').html('Last caller: blue');
});
$('#container').on('mouseleave', function(){
$('#results3').html('Last caller: green');
$('#results1').html('');
});
$('#child').on('mouseleave', function(){
$('#results3').html('Last caller: blue');
$('#results2').html('');
});
#container {
height: 100px;
width: 100px;
background-color: green;
}
#child {
height: 50px;
width: 50px;
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container">
<div id="child">
</div>
</div>
<pre id="results1"></pre>
<pre id="results2"></pre>
<pre id="results3"></pre>
然而,你不能这样做(仅更改HTML和CSS):
$('#container').on('mouseover', function(){
$('#results1').html('Inside green square');
$('#results3').html('Last caller: green');
});
$('#child').on('mouseover', function(){
$('#results2').html('Inside blue square');
$('#results3').html('Last caller: blue');
});
$('#container').on('mouseleave', function(){
$('#results3').html('Last caller: green');
$('#results1').html('');
});
$('#child').on('mouseleave', function(){
$('#results3').html('Last caller: blue');
$('#results2').html('');
});
#container {
height: 100px;
width: 100px;
background-color: green;
}
#child {
position: absolute;
top: 10px;
height: 50px;
width: 50px;
background-color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="container"></div>
<div id="child"></div>
<pre id="results1"></pre>
<pre id="results2"></pre>
<pre id="results3"></pre>
我能想到的唯一解决方法是在触发元素的父元素上设置监听器,检查鼠标位置并将其与元素位置进行比较。