0

当我悬停容器时,如何将此悬停效果应用于此容器中的所有图像?

http://www.photoshop-plus.co.uk/2012/05/21/jquery-color-fade-hover-effect/

jQuery

$(document).ready(function(){
    $("img.grey").hover(
    function() {
    $(this).stop().animate({"opacity": "0"}, "slow");
    },
    function() {
    $(this).stop().animate({"opacity": "1"}, "slow");
    });
});

CSS

<ul class="gallery">
<li>
<img src="images/01_grey.gif" class="grey" />
<img src="images/01_color.gif" class="color" />
</li>

<li>
<img src="images/02_grey.gif" class="grey" />
<img src="images/02_color.gif" class="color" />
</li>
</ul>
4

1 回答 1

0

这是你如何实现它:http: //jsfiddle.net/xEuD7/

请注意,您需要实现CSS并将JavaScript 插件导入您的页面!

.gallery li {
    float: left;
    margin-right: 20px;
    list-style-type: none;
    margin-bottom: 20px;
    display: block;
    height: 130px;
    width: 130px;
    position: relative;
}
img.grey {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 10;
}
img.color {
    position: absolute;
    left: 0;
    top: 0;
}

更新:

$(document).ready(function(){
    $("img.grey").hover(
    function() {
        $(this).parents('.gallery').find("img.grey").stop().animate({"opacity": "0"}, "slow");
    },
    function() {
        $(this).parents('.gallery').find("img.grey").stop().animate({"opacity": "1"}, "slow");
    });
});
于 2013-03-13T03:44:36.093 回答