2013-03-13 65 views
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> 
+2

你嘗試過這麼遠嗎?另外請確保你閱讀了常見問題stackoverflow.com/faq,因爲這個問題不是你應該問的問題。 – N1ck 2013-03-13 03:14:00

回答

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; 
} 

UPDATE:

$(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"); 
    }); 
}); 
+0

已經在Dreamweaver中打開了,謝謝。但是如何在懸停ul的情況下對畫廊中的所有圖像執行懸停效果? – rxjudy 2013-03-13 03:50:13

+0

查看更新的答案 – 2013-03-13 06:21:04

+0

這絕對好!非常感謝塞繆爾! – rxjudy 2013-03-13 06:35:52