How do I make a rollover using png and jquery?

一笑奈何 提交于 2019-12-24 11:15:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!