简体   繁体   English

悬停依赖于两个元素的行为:悬停A或B时显示A

[英]Hover dependant behavior of two elements : when A or B are hovered show A

here is my CodePen demo or you can run the snippet below. 这是我的CodePen 演示,或者您可以运行下面的代码段

In the original script, the front face of the cube is a slider, and when I hover my 'info-box' it shows the right side of it with some description ( <p> an <a> ). 在原始脚本中,多维数据集的正面是一个滑块,当我将鼠标悬停在“信息框”上时,它会在右侧显示一些说明( <p><a> )。

The expected behavior is that as long as the user stays on the description, the element keeps having the .hover class given in the $('#info-box').hover() function 预期的行为是, 只要用户停留在描述上,该元素就会一直具有$('#info-box').hover()函数中提供的.hover$('#info-box').hover()

All was working fine until i tested it on chrome :(... 一切正常,直到我在chrome上测试它为止:(...

From what I understand, it seems to fires multiples mouseOver/mouseOut events when hovering and it messes and flicker everything up. 据我了解,它似乎在悬停时会触发多个mouseOver/mouseOut事件,并弄乱和闪烁所有内容。

Should I use a setTimeout ? 我应该使用setTimeout吗?

 $('.slide-info').click(function() { $(this).parent().toggleClass('hover'); }) .hover(function() { $(this).parent().addClass('hover'); }, function() { $(this).parent().removeClass('hover'); }); $('.right').hover(function() { $(this).parent().parent().addClass('hover'); }, function() { $(this).parent().parent().removeClass('hover'); }); 
 h1 { text-align: center; } body { background-color: #333; } .Cube-container { width: 500px; top: 20px; height: 150px; perspective: 1000px; position: relative; margin-right: auto; margin-left: auto; transform-origin: 50% 50% -250px; } .Cube { transition: all .5s ease-out; transform-style: preserve-3d; backface-visibility:hidden; } .front, .right { height: 150%; text-align: center; padding-top: 10px; backface-visibility: hidden; } .Cube-container.hover .Cube { transform: rotateY(90deg); transform-origin: 50% 50% -250px; } .front { transform-style: preserve-3d; transition: all .5s ease-out; background-color: #fc8; position: relative; } .right { background-color: #8cf; position: absolute; top: 0px; left: 0px; height: calc(100% - 10px); /* because it takes in account the padding, i guess we can do some box-sizing: border box to avoid that...*/ width: 100%; transform: rotateY(-90deg) translateX(-100%); transform-origin: 0 0; } .ol /* OverLay */ { position: absolute; left: 0; top: 0; width: 100%; height: 100%; } .slide-info { width: auto; height: auto; background-color: rgba(0, 0, 0, 0.5); padding: 0 15px; cursor: pointer; color: #fff; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="Cube-container"> <div class="ol Cube"> <div class="ol right"> <h2>Right side</h2> <p>While we hover that side, parent element keeps having the .hover class, making it visible</p> </div> <div class="ol front"> <h2>Front</h2> <p>Hover the info box please :)</p> </div> </div> <div class="ol slide-info"> <h3>INFO</h3> </div> </div>http://stackoverflow.com/questions/ask# 

The problem was that I used backface-visibility: hidden on parent element. 问题是我使用了backface-visibility: hidden在父元素上。 (see commented line in snippet) (请参见摘要中的注释行)

Crazy but that solved my problem on Chrome browser, now everything works fine. 疯狂,但这解决了我在Chrome浏览器上的问题,现在一切正常。

 $('.slide-info').click(function() { $(this).parent().toggleClass('hover'); }) .hover(function() { $(this).parent().addClass('hover'); }, function() { $(this).parent().removeClass('hover'); }); $('.right').hover(function() { $(this).parent().parent().addClass('hover'); }, function() { $(this).parent().parent().removeClass('hover'); }); 
 h1 { text-align: center; } body { background-color: #333; } .Cube-container { width: 500px; top: 20px; height: 150px; perspective: 1000px; position: relative; margin-right: auto; margin-left: auto; transform-origin: 50% 50% -250px; } .Cube { transition: all .5s ease-out; transform-style: preserve-3d; /*backface-visibility:hidden; <-- Causing the problem */ } .front, .right { height: 150%; text-align: center; padding-top: 10px; backface-visibility: hidden; } .Cube-container.hover .Cube { transform: rotateY(90deg); transform-origin: 50% 50% -250px; } .front { transform-style: preserve-3d; transition: all .5s ease-out; background-color: #fc8; position: relative; } .right { background-color: #8cf; position: absolute; top: 0px; left: 0px; height: calc(100% - 10px); /* because it takes in account the padding, i guess we can do some box-sizing: border box to avoid that...*/ width: 100%; transform: rotateY(-90deg) translateX(-100%); transform-origin: 0 0; } .ol /* OverLay */ { position: absolute; left: 0; top: 0; width: 100%; height: 100%; } .slide-info { width: auto; height: auto; background-color: rgba(0, 0, 0, 0.5); padding: 0 15px; cursor: pointer; color: #fff; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="Cube-container"> <div class="ol Cube"> <div class="ol right"> <h2>Right side</h2> <p>While we hover that side, parent element keeps having the .hover class, making it visible</p> </div> <div class="ol front"> <h2>Front</h2> <p>Hover the info box please :)</p> </div> </div> <div class="ol slide-info"> <h3>INFO</h3> </div> </div>http://stackoverflow.com/questions/ask# 

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

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