最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - show the description when hover the image - Stack Overflow

programmeradmin1浏览0评论

I have this 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>

i want when i go over the image with the mouse to display whatever i want in that span, even an image of a but button or bold text. something like this EXAMPLE

Thanks in advance!

I have this 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>

i want when i go over the image with the mouse to display whatever i want in that span, even an image of a but button or bold text. something like this EXAMPLE

Thanks in advance!

Share Improve this question asked Dec 12, 2012 at 18:03 AbudeAbude 2,1628 gold badges36 silver badges60 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 3

Try something like this - DEMO

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);
    },
})

Try this

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

});​

reference http://jsfiddle/puu5u/9/

You can do this in CSS

HTML

​<div class="image">
<p class="caption">Some info related the pic</p>
<img src="http://i.imgur./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;}​

Demo - http://jsfiddle/hqLjz/

Try this:

$('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();
});​

FIDDLE

发布评论

评论列表(0)

  1. 暂无评论