问题
I reverse coded a script I found online and it works well, the only problem is that the hover image loads at complete visibility until the action of hover occurs. This is the script:
$(document).ready(function()
{
$("img.b").hover(
function() {
$(this).stop().animate({"opacity": "1"}, "slow");
},
function() {
$(this).stop().animate({"opacity": "0"}, "slow");
});
});
</script>
This is the CSS file:
<style>
div.fadehover {
position: relative;
}
img.b {
position: absolute;
left: 0;
top: 0;
z-index: 10;
}
img.a {
position: absolute;
left: 0;
top: 0;
}
</style>
And this is the body code:
<div class="fadehover">
<a href=""><img src="portfolio_a.png" alt="" class="a" />
<img src="portfolio_b.png" alt="" class="b" /></a>
</div>
You can view a sample of it here: http://www.kaimeramedia.com/derek/Website/test.html
回答1:
Alter your CSS to have it hide onload:
img.b {
position: absolute;
left: 0;
top: 0;
z-index: 10;
opacity: 0;
filter: alpha(opacity=0);
}
The filter:alpha(opacity=0);
line is for I.E.
Here is a jsfiddle of the above solution: http://jsfiddle.net/jasper/CyJXD/
来源:https://stackoverflow.com/questions/8057417/how-do-i-make-a-rollover-using-png-and-jquery