I want to be able to fade one image into another on hover and then fade out the hovered image once the mouse leaves the object. Because its tightly packed within a DIV i do not want any space around it, so was trying to use just SPAN which is not working. Any idea?
MY scripts are the following:
<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 />
I have a little white space below the first image. Anyway to get rid of it?
How it looks: http://img805.imageshack.us/img805/7417/imgct.png
I want to get rid of the white space in between the first image on top from the image thats green.
my New HTML page:
<!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>
But now i have two images, the second one(green) went under the first one(black) and the third one(yellow) is right below the black one.
Here is the example: http://img266.imageshack.us/img266/9557/imgdu.png
Remove the
top:0px; left:0px;and add the above code and that should sort it out.