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 badges4 Answers
Reset to default 3Try 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