mousemove事件在2个重叠的div上

时间:2017-03-07 08:49:53

标签: javascript jquery css

我有2个重叠的div,需要在两者上执行相同的mousemove事件。我不能使用具有冒泡效果的嵌套div。  我怎样才能做到这一点?我不能使用具有冒泡效果的嵌套div。

$(".one").mousemove(function(){
  console.log("something")
})

$(".two").mousemove(function(){
  console.log("something else")
})
.one{
    background-color:red;
    position:absolute;
    left:0;
    top:0;
    width:100px;
    height:100px;
 
    
}
.two{
    color:blue;
    position:absolute;
    left:0;
    top:0;
    width:100px;
    height:100px;
  
    
}
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>

  
 
    <div class="one">
        Content one
    </div>
    <div class="two">
        Content two
    </div>

</body>
</html>

谢谢。

1 个答案:

答案 0 :(得分:3)

&#13;
&#13;
$(".one").mousemove(function(){
  console.log("something");
});

$(".two").mousemove(function(){
  console.log("something else");
  $(".one").mousemove();
});
&#13;
.one{
    background-color:red;
    position:absolute;
    left:0;
    top:0;
    width:100px;
    height:100px;
 
    
}
.two{
    color:blue;
    position:absolute;
    left:0;
    top:0;
    width:100px;
    height:100px;
  opacity: .95;
    
}
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="one">
        Content one
</div>
<div class="two">
        Content two
</div>
&#13;
&#13;
&#13;