简体   繁体   English

隐藏说明直到用户将鼠标悬停在图片上?

[英]Description hidden until user hovers over the image?

I'm looking for some help with this project. 我正在寻找有关此项目的帮助。 I want to be able to hover over the image and this black box pops up with the description in it. 我希望能够将鼠标悬停在图像上,并弹出带有说明的黑框。 Can I get some examples of how I would go about doing this? 我可以举一些我将如何做的例子吗? Thank you all so much for the help! 非常感谢大家的帮助!

what I'm looking to do when user hovers over the image for a description 用户将鼠标悬停在图像上以进行描述时我要做什么

在此处输入图片说明

with pure css you can do something like this 使用纯CSS,您可以执行以下操作

 #image_description { display: none; background-color : #333; color : #fff; padding : 50px; } #the_image:hover~#image_description{ display: block; } 
 <img src="https://placehold.it/350x150" id="the_image"> <div id="image_description">SomeDescription</div> 

with jQuery you can do something like this 使用jQuery,您可以执行以下操作

 $(document).ready(function(){ $("#the_image").hover(function(){ $("#image_description").fadeIn(); }, function(){ $("#image_description").fadeOut(); }); }); 
 #image_description { display : none } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <img src="https://placehold.it/350x150" id="the_image"> <div id="image_description">SomeDescription</div> 

@Allan Empalmado is correct. @Allan Empalmado是正确的。 But you can add CSS transitions to make it flow in and out smoothly, with pure CSS transition property. 但是您可以添加CSS过渡,以使其具有纯CSS过渡属性,从而顺畅地流入和流出。 Add this to the code... 将此添加到代码中...

#image_description {
    background-color: #333;
    color: #fff;
    oveflow:hidden;
    -webkit-transition: max-height 0.9s ease;
    -moz-transition: max-height 0.9s ease;
    transition: max-height 0.9s ease;
    max-height:0;
}
#the_image:hover ~ #image_description{
    max-height: 150px; 
}


The -webkit- and -moz- make the CSS cross-browser. -webkit--moz-使CSS跨浏览器。 it is a simple google search to find other properties you can manipulate with the transition properties. 这是一个简单的Google搜索,可以找到您可以使用过渡属性进行操作的其他属性。
Hopefully you can find other things you can do to enhance Alans sample code. 希望您能找到其他可以增强Alans示例代码的方法。 happy coding !! 快乐编码!

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

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