将鼠标悬停在图像上时显示说明



我有这个 HTML :

<div class="left_area">
 <div class="caption"> 
   <a href="<?php echo $URL; ?>"><img src="<?php echo $images; ?>" alt="<?php echo $name; ?>" /></a>
   <span>test</span></div>
</div>

我希望当我用鼠标浏览图像时,在该范围内显示我想要的任何内容,甚至是但是按钮或粗体文本的图像。 像这样的例子

提前感谢!

尝试这样的事情 - 演示

.CSS

.caption {
    position: relative;
    width: 300px;
    cursor: pointer;
}
span {
    display: none;
    position: absolute;
    left: 0;
    top: 0;
    background: rgba(0, 0, 0, .7);
    height: 200px;
    width: 300px;
    color: #fff;
}

.JS

$('.caption').on({
    mouseover: function() {
        $(this).find('span').fadeIn(200);
    },
    mouseout: function() {
        $(this).find('span').stop().fadeOut(200);
    },
})

试试这个

$(document).ready(function(){
  $('a','.caption').mouseenter(function(){
     $('span',$(this).parent()).show();
  }).mouseleave(function(){
     $('span',$(this).parent()).hide();
  });

});

参考 http://jsfiddle.net/puu5u/9/

你可以在 CSS 中执行此操作

.HTML

​<div class="image">
<p class="caption">Some info related the pic</p>
<img src="http://i.imgur.com/VMaxsb.jpg" />
</div>​

.CSS

.image {float: left; position: relative;}
.image .caption {width: 100%; height: 100%; background: rgba(0,0,0,0.82); position: absolute; color: #fff; display: none}
.image:hover​ .caption {display: block;}​

演示 - http://jsfiddle.net/hqLjz/

试试这个:

$('ul li').mouseenter(function(){
    var image= $(this).find('img'),
        caption = $(this).find('div');
    caption.width(image.width());
    caption.height(image.height());
    caption.fadeIn();
}).mouseleave(function(){
     var image= $(this).find('img'),
        caption = $(this).find('div');
    caption.width(image.width());
    caption.height(image.height());
    caption.fadeOut();
});​

小提琴

最新更新