2009-07-29 138 views
1

我有一個圖像列表,當DOM被加載時,這些圖像都被設置爲40%不透明度。JQuery元素不透明度設置

我需要這些圖像中的第一個保持100%的不透明度,因爲其他的圖像會消失。

我的代碼如下,但我似乎無法讓第一個圖像保持在100%。

$j(document).ready(function() { 

    fadeDownImages(); 



    fadeDownImages = function() { 
      $j("ul.promo img").fadeTo(1500, 0.2); 
      $j("ul.promo img").hover(function(){ 
      $j(this).fadeTo(300, 1.0); // This should set the opacity to 100% on hover 
      },function(){ 
      $j(this).fadeTo(200, 0.2); // This should set the opacity back to 60% on mouseout 

    }); 
    }; 

    $j("ul.promo img:first-child").fadeIn(200, 1.0); 

任何幫助非常讚賞

回答

0

它看起來並不像你真的做任何嘗試得到的第一個圖像保持100%的不透明度。試試這個:

fadeDownImages = function() { 
      $j("ul.promo img:gt(0)").fadeTo(1500, 0.2); 
      $j("ul.promo img:gt(0)").hover(function(){ 
      $j(this).fadeTo(300, 1.0); // This should set the opacity to 100% on hover 
      },function(){ 
      $j(this).fadeTo(200, 0.2); // This should set the opacity back to 60% on mouseout 

}); 
+0

感謝您的幫助 @cpharmston - 這似乎並沒有爲所有圖像的工作,現在留100%。我沒有得到任何錯誤。如果我刪除:not(:first-child),它允許圖像淡入淡出。 @chaos - 這也沒有工作...什麼是:GT(1)做的? 謝謝 – Martin 2009-07-29 12:25:46

3
$j(document).ready(function() { 
    fadeDownImages = function() { 
     var imgs = $j("ul.promo img:not(:first-child)"); 
     imgs.fadeTo(1500, 0.2); 
     imgs.hover(function(){ 
      $j(this).fadeTo(300, 1.0); 
     },function(){ 
      $j(this).fadeTo(200, 0.2); 
     }); 
    }; 
    $j("ul.promo img:first-child").fadeIn(200, 1.0); 
} 
0

我把@cpharmston建議和改變:第一,孩子一個選擇器類和它的工作!

fadeDownImages = function() { 
    var imgs = $j("ul.promo img:not(.bollocks)"); 
    imgs.fadeTo(1500, 0.2); 
    imgs.hover(function(){ 
     $j(this).fadeTo(300, 1.0); 
    },function(){ 
     $j(this).fadeTo(200, 0.2); 
    }); 
}; 
$j("ul.promo img:first-child").fadeIn(200, 1.0); 

感謝您的幫助