简体   繁体   English

多个div重叠时如何组织事件

[英]how to organize events when multiple divs overlap

I have four divs, box1, box2, box3 and box4, and use rotate to let them overlap by order. 我有四个div,box1,box2,box3和box4,并使用rotate使其按顺序重叠。 i use jquery hover function to show certain tips when mouse is over the target dev, but i find that the event is chaotic,and disturbed. 当鼠标悬停在目标开发人员上时,我使用了jquery hover功能来显示某些提示,但是我发现该事件是混乱且受干扰的。 how to handler the event and prevent one div event affect the other. 如何处理该事件并防止一个div事件影响另一个事件。 Here is my code: 这是我的代码:

html: HTML:

<div class="wrap">
  <div class="box1"></div>
  <div class="box2"></div>
  <div class="box3"></div>
  <div class="box4"></div>
</div>

css: CSS:

 .wrap {
    width: 400px;
    height: 400px;
    position:relative;

-webkit-perspective: 700px;
-moz-perspective: 700px;
-ms-perspective: 700px;
perspective: 700px;
 }
 .wrap div {
    position:absolute;
    left:50%;top:50%;

     -webkit-transform: rotateX(69deg) rotateY(0deg) rotateZ(0deg) scaleX(.73) scaleY(.73) scaleZ(1);
-moz-transform: rotateX(69deg) rotateY(0deg) rotateZ(0deg) scaleX(.73) scaleY(.73) scaleZ(1);
-ms-transform: rotateX(69deg) rotateY(0deg) rotateZ(0deg) scaleX(.73) scaleY(.73) scaleZ(1);
transform: rotateX(69deg) rotateY(0deg) rotateZ(0deg) scaleX(.73) scaleY(.73) scaleZ(1);
 }
.box1 {
    width:400px;
    height:400px;
    margin-left: -200px;margin-top:-200px;
}
.box2 {
    width:300px;
    height:300px;
    margin-left: -150px;margin-top:-150px;
}
.box3 {
    width:200px;
    height:200px;
    margin-left: -100px;margin-top:-100px;
}
.box4 {
    width:100px;
    height:100px;
    margin-left: -50px;margin-top:-50px;
}

js: JS:

$(".wrap div").hover(function(event){
    console.log(event.currentTarget);
},function(event) {
    console.log(event.currentTarget);
});

Try the hover effect based on class name. 尝试基于类名的悬停效果。

    $(".wrap > .box1 ").hover(function(){
         console.log("hover in "+event.currentTarget);
     },function(){
    console.log("hover out "+event.currentTarget);
 });

$(".wrap > .box2 ").hover(function(){
      console.log("hover in "+event.currentTarget);
       },function(){
      console.log("hover out "+event.currentTarget);
 });

You can add simlarily for box3 and box4. 您可以同时为box3和box4添加。 You can further optimize this using logic. 您可以使用逻辑进一步对此进行优化。 I have add ">" symbol only because the hover effect is limited to direct child's of wrap class div only.. 我仅添加“>”符号是因为悬停效果仅限于包装类div的直接子级。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM