我希望能够在悬停时将一个图像淡入另一个图像,然后在鼠标离开对象后淡出悬停的图像。因为它紧紧地包装在一个 DIV 中,所以我不希望它周围有任何空间,所以试图只使用不起作用的 SPAN。任何想法?我的脚本如下:
<style>
.fade {
position: relative;
border: 0;
margin: 0 auto;
padding: 0;
}
.fade div {
position: absolute;
top: 0;
left: 0;
display: none;
height: 100px;
width: 240px;
border: 0;
margin: 0 auto;
padding: 0;
}
-->
</style>
<script type="text/javascript">
<!--
$(function () {
// find the div.fade elements and hook the hover event
$('span.fade').hover(function() {
// on hovering over find the element we want to fade *up*
var fade = $('> div', this);
// if the element is currently being animated (to fadeOut)...
if (fade.is(':animated')) {
// ...stop the current animation, and fade it to 1 from current position
fade.stop().fadeTo(250, 1);
} else {
fade.fadeIn(250);
}
}, function () {
var fade = $('> div', this);
if (fade.is(':animated')) {
fade.stop().fadeTo(3000, 0);
} else {
fade.fadeOut(3000);
}
});
});
//-->
</script>
HTML:
<span class="fade">
<img src="theImages/sApproveBW.jpg" alt="Who we are" />
<div>
<img src="theImages/sApprove.jpg" alt="Who we are" />
</div>
</span><img src="theImages/bApprove.jpg" height=100 width=240 /><br><img src="theImages/tApprove.jpg" height=100 width=240 />
我在第一张图片下方有一点空白。无论如何要摆脱它?
它的外观:http: //img805.imageshack.us/img805/7417/imgct.png
我想摆脱绿色图像顶部第一张图像之间的空白。
我的新 HTML 页面:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Fade Method 1 (two images)</title>
<style type="text/css" media="screen">
<!--
* {
margin: 0;
padding: 0;
}
img { border: 0;
display: block;
}
.fade {
position: absolute
}
.fade div {
position: absolute;
top: 0;
left: 0;
display: none;
height: 100px;
width: 240px;
}
-->
</style>
<script src="http://code.jquery.com/jquery-1.7.1.min.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
$(function () {
// find the div.fade elements and hook the hover event
$('span.fade').hover(function() {
// on hovering over find the element we want to fade *up*
var fade = $('> div', this);
// if the element is currently being animated (to fadeOut)...
if (fade.is(':animated')) {
// ...stop the current animation, and fade it to 1 from current position
fade.stop().fadeTo(250, 1);
} else {
fade.fadeIn(250);
}
}, function () {
var fade = $('> div', this);
if (fade.is(':animated')) {
fade.stop().fadeTo(3000, 0);
} else {
fade.fadeOut(3000);
}
});
});
//-->
</script>
</head>
<body id="page">
<span class="fade">
<img src="theImages/sApproveBW.jpg" alt="Who we are" />
<div>
<img src="theImages/sApprove.jpg" alt="Who we are" />
</div>
</span>
<img class=t src="theImages/bApprove.jpg" height=100 width=240 />
<img class=t src="theImages/tApprove.jpg" height=100 width=240 />
</body>
</html>
但现在我有两张图片,第二张(绿色)在第一张(黑色)下方,第三张(黄色)在黑色下方。这是示例:http: //img266.imageshack.us/img266/9557/imgdu.png