<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="JS代码,黑白特效,图片特效,鼠标滑过,CSS,jQuery特效,JS图片特效,JS广告代码,JS常用代码" />
<meta name="description" content="jquery+css实现鼠标滑过图片黑白显示的特效,更多黑白特效,图片特效,鼠标滑过,CSS,jQuery特效代码请访问脚本之家JS代码频道。" />
<title>jquery+css实现鼠标滑过图片黑白显示的特效_脚本之家</title>
<style type="text/css">
body {
height: 100%;
margin: 0;
padding: 0;
font: normal 10px Verdana, Arial, Helvetica, sans-serif;
background: #fff;
position: relative;
}
h1 {
text-align: center;
font-weight: normal;
font-size: 2.5em;
}
h1 small {
display: block;
font-size: 0.7em;
color: #999;
}
img {border: none;}
ul.gallery {
width: 708px;
list-style: none;
margin: 0 auto; padding: 0;
}
ul.gallery li {
float: left;
margin: 10px; padding: 0;
text-align: center;
border: 1px solid #ccc;
-moz-border-radius: 3px; /*--CSS3 Rounded Corners--*/
-khtml-border-radius: 3px; /*--CSS3 Rounded Corners--*/
-webkit-border-radius: 3px; /*--CSS3 Rounded Corners--*/
display: inline; /*--Gimp Fix aka IE6 Fix--*/
}
ul.gallery li a.thumb {
width: 204px;
height: 182px;
padding: 5px;
border-bottom: 1px solid #ccc;
cursor: pointer;
}
ul.gallery li span { /*--Used to crop image--*/
width: 204px;
height: 182px;
overflow: hidden;
display: block;
}
ul.gallery li a.thumb:hover {
background: #333;
}
ul.gallery li h2 {
font-size: 1em;
font-weight: normal;
text-transform: uppercase;
margin: 0; padding: 10px;
background: #f0f0f0;
border-top: 1px solid #fff; /*--Subtle bevel effect--*/
}
ul.gallery li a {text-decoration: none; color: #777; display: block;}
</style>
<script type="text/javascript" src="images/jquery.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("ul.gallery li").hover(function() { //On hover...
var thumbOver = $(this).find("img").attr("src"); //Get image url and assign it to 'thumbOver'
//Set a background image(thumbOver) on the <a> tag
$(this).find("a.thumb").css({'background' : 'url(' + thumbOver + ') no-repeat center bottom'});
//Fade the image to 0
$(this).find("span").stop().fadeTo('normal', 0 , function() {
$(this).hide() //Hide the image after fade
});
} , function() { //on hover out...
//Fade the image to 1
$(this).find("span").stop().fadeTo('normal', 1).show();
});
});
</script>
</head>
<body>
<h1><a href="http://www.sohtanaka.com/web-design/greyscale-hover-effect-w-css-jquery/" style="color: #333; text-decoration: none;">Greyscale Hover Effect w/ CSS & jQuery</a><br /></h1>
<ul class="gallery">
<li>
<a href="#" class="thumb"><span><img src="images/sushiand.gif" alt="" /></span></a>
<h2><a href="#">Sushi & Robots</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/garysrea.gif" alt="" /></span></a>
<h2><a href="#">Gary's Life</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/cubescri.gif" alt="" /></span></a>
<h2><a href="#">Cube Scripts</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/ryankeis.gif" alt="" /></span></a>
<h2><a href="#">Ryan Keiser</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/ricardog.gif" alt="" /></span></a>
<h2><a href="#">Ricardo Gimenes</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/foodteas.gif" alt="" /></span></a>
<h2><a href="#">Food Tease</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/lemonsta.gif" alt="" /></span></a>
<h2><a href="#">Lemon Stand</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/heyindy_.gif" alt="" /></span></a>
<h2><a href="#">Hey Indy</a></h2>
</li>
<li>
<a href="#" class="thumb"><span><img src="images/ngenwork.gif" alt="" /></span></a>
<h2><a href="#">nGen Works</a></h2>
</li>
</ul>
<div style="text-align:center; clear:both; margin:5px auto">
<p>代码整理:<a href="http://www.jb51.net/" target="_blank">脚本之家</a> 更多相关效果,请到脚本之家 <a href="http://www.jb51.net/jiaoben/guanggao1.html" target="_blank">脚本下载</a>栏目</p>
<p>*尊重他人劳动成果,转载请自觉注明出处!注:此代码仅供学习交流,请勿用于商业用途。</p>
<p><a href="http://sc.jb51.net" target="_blank">脚本之家素材中心</a>整理。</p>
<p><script src="/js/js-preview-728x90.js"></script><br /><br /><br /><center><script src="/js/tj.js"></script></center></p>
</div>
</body>
</html>