有时候有的情况有的地方需要一些图片的渐变效果,比如黑白变彩色,模糊变清晰。
这里介绍一个简单的方法[bavotasan]用JQuery来实现这样的效果。
第一步
当然是加载jquery库,可以选择从jquery官网下载最新的版本然后在网页头部加上如下语句。
<script src="http://你的网址.com/jquery.js" type="'text/javascript'"></script>
或者直接从google加载,这样更能提高性能。
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.js'></script>
第二步道最后一步
准备2张图片。


再接着是function和css及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=UTF-8" />
<title>jQuery Hover Effect</title>
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.js'></script>
<script>
$(document).ready(function(){
$("img.a").hover(
function() {
$(this).animate({"opacity": "0"}, "slow");
},
function() {
$(this).animate({"opacity": "1"}, "slow");
});
});
</script>
<style>
div.fadehover {
position: relative;
}
img.a {
position: absolute;
left: 0;
top: 0;
z-index: 10;
}
img.b {
position: absolute;
left: 0;
top: 0;
}
</style>
</head>
<body>
<div class="fadehover"><div><img src="cbavota-bw.jpg" alt="" class="a" /></div><div><img src="cbavota.jpg" alt="" class="b" /></div>
</body>
</html>
文章添加 :
果酱
