简体   繁体   English

将div悬停在一系列类似的内容中,显示另一个

[英]hover one div in a series of similar, show the other

guys. 伙计们 I have several goods with description. 我有几种带有说明的商品。 I need "tile-description" appear when I hover over a "middle tile". 当我将鼠标悬停在“中间磁贴”上时,需要显示“拼贴描述”。 Besides, I need a border around the "large-tile" on hover. 此外,在悬停时,我需要在“大图块”周围添加边框。 Here is the mark-up and some js that I used, but it didn't work for me. 这是我使用的标记和一些js,但对我而言不起作用。 Help me, please! 请帮帮我!

  $(".middle-tile").mouseover(function(){ $(this).parent().siblings().css('opacity', 1); }); $(".middle-tile").mouseout(function(){ $(this).parent().siblings().css('opacity', 0); }); 
 .tile-description{ position: absolute; top: 100%; background-color: white; z-index: 10; opacity: 0; } 
 <div class="large-tile"> <div class="middle-tile"> <div class="tile-data"> <div class="tile-img"><a href=""><img src="img/item-2.jpg" alt="" ></a></div> <div class="tile-title"><a href="">Title</a></div> </div> <button class="btn price">3 697</button> </div> <div class="tile-description"> <p>Some specs</p> </div> </div> 

Use find instead of sibling when you use with parent or just sibling without parent as below: 使用find的,而不是sibling当你使用parent或只是sibling没有parent如下:

$(this).parent().find('.tile-description').css('opacity', 1);

DEMO 演示

Or 要么

$(this).siblings('.tile-description').css('opacity', 1);

DEMO 演示

Just use as CSS rule: 只是用作CSS规则:

.middle-tile:hover + .tile-description {
    opacity: 1;
}

-DEMO (using transition btw) -DEMO(使用过渡btw)

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

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