简体   繁体   English

将鼠标悬停在另一个div上时如何显示div

[英]How to display a div when hovering over another div

Here my first div shows an image. 在这里,我的第一个div显示了一张图片。 If you mouse hover on the image then it should show another div named hdiv . 如果将鼠标悬停在图像上,则它应显示另一个名为hdiv div。

Here $pitem[6] return data from database with php for loop. 这里$ pitem [6]用php for loop从数据库返回数据。

CODE

<div class="pcimga">
    <div class="pcimg"><img src="Portfolio_Image/'.$pitem[6].'" class="pcimg" /></div>

        <div class="hdiv" style="display:none;">
           <span class=" butnn"><a data-toggle="modal" href="#myModal'.$pitem[0].'">View</a>
        </div>          
</div>

Try this 尝试这个

$('.pcimga').hover(function() {
    $(this).find('.hdiv').show();
}, function(){
    $(this).find('.hdiv').hide();
});

Check it here JsFiddle 在这里检查 JsFiddle

try this... 尝试这个...

.pgimga:hover~.hdiv
{
display:block;
}

let me know if you want any further guidance.. 让我知道您是否需要任何进一步的指导。

You can do it with pure CSS: 您可以使用纯CSS来做到这一点:

1. When .hdiv is next to .pcimg 1.当 .hdiv 毗邻 .pcimg

.pcimg:hover+.hdiv{
    display:block !important;
}

Fiddle 小提琴

2. When there is gap between .hdiv and .pcimg 2. .hdiv .pcimg 之间存在间隙时

.pcimg:hover~.hdiv{
    display:block !important;
}

Fiddle 小提琴

Note : Internal styles have higher priority than External styles.So for giving External styles more priority !important is needed 注意:内部样式的优先级高于外部样式,因此要为外部样式赋予更高的优先级!important

Try this in CSS. 在CSS中尝试一下。 You need to use !important to override the inline style "display:none" 您需要使用!important覆盖内联样式“ display:none”

.pcimg:hover+.hdiv
{
    display:inherit !important;
}

You can do it like this with onmouseover and onmouseout events using jquery: 您可以使用jquery使用onmouseover和onmouseout事件来做到这一点:

<div class="pcimga">
    <div class="pcimg"><img onmouseover='$(".hdiv").show();'  onmouseout='$(".hdiv").hide();' src="Portfolio_Image/'.$pitem[6].'" class="pcimg" /></div>

        <div class="hdiv" style="display:none;">
           <span class=" butnn"><a data-toggle="modal" href="#myModal'.$pitem[0].'">View</a>
        </div>          
</div>

if you have multiple instances of this block, all of the images will be visible though. 如果您有该块的多个实例,则所有图像都将可见。 to distinguish which one is hovered you can send hideDiv(this) and get which image hovered to show appropriate image. 要区分悬停的图像,可以发送hideDiv(this)并获得悬停的图像以显示适当的图像。

展示<div>当悬停在另一个 div 及其子项上时</div><div id="text_translate"><p>我有一个 HTML div,里面有孩子。 我有一个附加到 div 的 jQuery 鼠标悬停事件。 鼠标悬停时,我显示另一个 div,鼠标悬停时,我隐藏它。</p><p> 但是,当我将鼠标悬停在“premiumlink”div 上时,一切正常,但是当我将鼠标移到 div 的一个子项上时,有条件显示的 div 会隐藏,但随后 jQuery 发现父 div 仍在悬停,所以它再次显示它。 然后,如果我将 cursor 移回父 div,则该 div 被隐藏然后再次显示。</p><p> 我怎样才能让鼠标悬停和鼠标悬停适用于所有孩子,而不是这个跳跃的 state?</p><p> 这是我的 HTML</p><pre> &lt;div class="platinumlevel" id="premiumlink"&gt; &lt;h1&gt; &lt;img src="~/Content/Images/colorworld.png" alt="Logo" class="eventimage" /&gt; &lt;a href="@Url.Action("Exhibitor1Attendee", "Home")" class="landing"&gt;Company Name&lt;/a&gt; &lt;/h1&gt; &lt;div id="demopreview" style="display: none;"&gt; I should be displayed when "premiumlink" and all it's children are mouseovered &lt;/div&gt; &lt;/div&gt;</pre><p> JS</p><pre> $("#premiumlink").mouseover(function () { $('#demopreview').show(1000); }).mouseout(function () { $('#demopreview').hide(1000); });</pre></div> - Display <div> when hovering over another div and its children

暂无
暂无

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

相关问题 展示<div>当悬停在另一个 div 及其子项上时</div><div id="text_translate"><p>我有一个 HTML div,里面有孩子。 我有一个附加到 div 的 jQuery 鼠标悬停事件。 鼠标悬停时,我显示另一个 div,鼠标悬停时,我隐藏它。</p><p> 但是,当我将鼠标悬停在“premiumlink”div 上时,一切正常,但是当我将鼠标移到 div 的一个子项上时,有条件显示的 div 会隐藏,但随后 jQuery 发现父 div 仍在悬停,所以它再次显示它。 然后,如果我将 cursor 移回父 div,则该 div 被隐藏然后再次显示。</p><p> 我怎样才能让鼠标悬停和鼠标悬停适用于所有孩子,而不是这个跳跃的 state?</p><p> 这是我的 HTML</p><pre> &lt;div class="platinumlevel" id="premiumlink"&gt; &lt;h1&gt; &lt;img src="~/Content/Images/colorworld.png" alt="Logo" class="eventimage" /&gt; &lt;a href="@Url.Action("Exhibitor1Attendee", "Home")" class="landing"&gt;Company Name&lt;/a&gt; &lt;/h1&gt; &lt;div id="demopreview" style="display: none;"&gt; I should be displayed when "premiumlink" and all it's children are mouseovered &lt;/div&gt; &lt;/div&gt;</pre><p> JS</p><pre> $("#premiumlink").mouseover(function () { $('#demopreview').show(1000); }).mouseout(function () { $('#demopreview').hide(1000); });</pre></div> - Display <div> when hovering over another div and its children 将鼠标悬停在div上时,如何将一个类添加到另一个div? - When hovering over a div, how to add a class to another div? 将鼠标悬停在 div 上时获取要显示的图像 - Get an image to display when hovering over an div 如何通过单击或悬停在第一个 div 元素旁边水平显示另一个 div 元素? 在第一个 div - how to display another div element next to the first div element horizontally by clicking or hovering? over the first div 将鼠标悬停在另一个div上时,将其定位到特定div - Target a specific div when hovering over another 将鼠标悬停在父div上时显示子div-Javascript - Display child div when hovering over parent div - Javascript 如何通过使用jQuery将鼠标悬停在另一个div上来滑动一个div? - How to slide a div by hovering over another div with jquery? jQuery:将鼠标悬停在另一个div上时,如何控制div的不透明度? - jQuery: how can I control a div's opacity when hovering over another div? 将鼠标悬停在一个 div 上时,如何将 class 添加到另一个 div? - How do add a class to another div, when hovering over one div? 将鼠标悬停在文本上并在另一个 div 中显示图像并且图像保持不变 - Hovering over text and display image in another div and the image stays
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM