LIVE DEMO
HTML:
<div class="addQ">
<img src="http://upload.wikimedia.org/wikipedia/commons/a/af/Bonsai_IMG_6426.jpg" />
</div>
<div class="addQ">
<img src="http://upload.wikimedia.org/wikipedia/commons/a/af/Bonsai_IMG_6426.jpg" />
</div>
CSS:
.addQ{
position:relative;
float:left;
margin:10px;
}
.addQ img {
position:relative;
vertical-align:middle;
width:300px;
}
.q {
position:absolute;
top:0;
box-shadow:inset 0px 0px 85px red;
-webkit-box-shadow:inset 0px 0px 85px red;
-moz-box-shadow:inset 0px 0px 85px red;
z-index: 3;
display:none;
}
问:
$(function(){
var addQimg = $('.addQ img');
var wi = addQimg.width();
var he = addQimg.height();
$('.addQ').each(function(){
$(this).append("<div class='q' />");
$(this).find('.q').width(wi).height(he);
}).on('mouseenter mouseleave', function( e ){
var opacity = e.type=='mouseenter' ? 1 : 0 ;
$(this).stop().find('.q').fadeTo(700, opacity);
});
});