以下是 jQuery鼠标悬停图片遮罩效果特效代码 的示例演示效果:
部分效果截图:
HTML代码(index.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>jQuery鼠标悬停图片遮罩效果</title>
<link rel="stylesheet" type="text/css" href="css/zzsc.css" media="all">
<script type="text/javascript" src="js/jquery.min.js"></script>
</head>
<body>
<!-- 代码 开始 -->
<!-- STAR_CONTAINER -->
<div id="container">
<div id="wrap-container" class="clearfix">
<div class="examples_body">
<ul class="bannerHolder">
<li>
<div class="banner">
<a href="#" >
<img height="125" width="125" alt="The Best Designs" src="images/aloha.jpg" />
</a>
<p class="companyInfo">图片信息一</p>
<div class="cornerTL"></div>
<div class="cornerTR"></div>
<div class="cornerBL"></div>
<div class="cornerBR"></div>
</div>
</li>
<li>
<div class="banner">
<a href="#/" >
<img height="125" width="125" alt="Mail Chimp" src="images/season1.jpg" />
</a>
<p class="companyInfo">图片信息二</p>
<div class="cornerTL"></div>
<div class="cornerTR"></div>
<div class="cornerBL"></div>
<div class="cornerBR"></div>
</div>
</li>
<li>
<div class="banner">
<a href="#/" >
<img height="125" width="125" alt="Mail Chimp" src="images/season2.jpg" />
</a>
<p class="companyInfo">图片信息三</p>
<div class="cornerTL"></div>
<div class="cornerTR"></div>
<div class="cornerBL"></div>
<div class="cornerBR"></div>
</div>
</li>
<li>
<div class="banner">
<a href="#/" >
<img height="125" width="125" alt="Mail Chimp" src="images/slamdunker.jpg" />
</a>
<p class="companyInfo">图片信息四</p>
<div class="cornerTL"></div>
<div class="cornerTR"></div>
<div class="cornerBL"></div>
<div class="cornerBR"></div>
</div>
</li>
<li>
<div class="banner">
<a href="#/" >
<img height="125" width="125" alt="Mail Chimp" src="images/seagaia_miyazaki.jpg" />
</a>
<p class="companyInfo">图片信息五</p>
<div class="cornerTL"></div>
<div class="cornerTR"></div>
<div class="cornerBL"></div>
<div class="cornerBR"></div>
</div>
</li>
</ul>
<!-- Examples body -->
</div>
</div>
<!-- /COPYRIGHT -->
</div>
<!-- END_CONTAINER -->
<script>
$(document).ready(function(){
// 0.4代表遮罩的透明度
$('.banner div').css('opacity',0.2);
$('.banner').hover(function(){
var el = $(this);
// 先淡出阴影,后淡入文字
el.find('div').stop().animate({width:200,height:200},'slow',function(){
el.find('p').fadeIn('fast');
});
},function(){
var el = $(this);
// 隐藏文字
el.find('p').stop(true,true).hide();
// 去掉遮罩
el.find('div').stop().animate({width:60,height:60},'fast');
}).click(function(){
// 点击图片时打开链接
window.open($(this).find('a').attr('href'));
});
});
</script>
<!-- 代码 结束 -->
</body>
</html>
CSS代码(zzsc.css):
html,body,p{border:0 none;margin:0;padding:0;outline-style:none;outline-width:0;vertical-align:baseline;font-size:12px;}
/*--------------------------------------------container--------------------------------------------*/
div#container{width:100%;margin:0 auto;overflow:hidden;}
div.examples_body{width:750px;margin:50px auto 0 auto;clear:both;overflow:hidden;position:relative;}
/* The main banner unordered list */
.bannerHolder{width:726px;margin:20px 0 15px 0;padding:20px 10px 20px 10px;background-color:#f7f7f7;border:1px solid #eee;overflow:hidden;/* CSS3 rounded corners */
-moz-border-radius:12px;-webkit-border-radius:12px;border-radius:12px;}
/* Hiding the bullets of the li elements:*/
.bannerHolder li{list-style:none;display:inline;}
/* The banner divs */
.banner{width:125px;height:125px;position:relative;overflow:hidden;float:left;display:inline;margin:0 10px}
/* The banner divs */
.banner img{display:block;border:none;}
/* The dark animated divs */
.banner div{position:absolute;z-index:100;background-color:#222;width:60px;height:60px;cursor:pointer;/*Setting a really big value for border-radiuswill make the divs perfect circles */
-moz-border-radius:100px;-webkit-border-radius:100px;border-radius:100px;}
/*Positioning the animated divs outside thecorners of the visible banner area:*/
.banner .cornerTL{left:-63px;top:-63px;}
.banner .cornerTR{right:-63px;top:-63px;}
.banner .cornerBL{left:-63px;bottom:-63px;}
.banner .cornerBR{right:-63px;bottom:-63px;}
/* The "Visit Company" text */
.banner p{width:100%;left:0;top:57px;z-index:200;position:absolute;font-family:Tahoma,Arial,Helvetica,sans-serif;color:#FFF;font-size:11px;text-align:center;cursor:pointer;display:none;/* hidden by default */
}