2009-04-20 49 views
1
$(document).ready(function(){ 
     // Hide all large images except the first one 
     $('#imageContainer img').hide().filter(':first').show(); 
     // Select all thumb links 
     $('#thumbContainer a').hover(function(event) { 
       // Hide all large images except for the one with the same hash as our thumb link 
       $('#imageContainer img').hide().filter(this.hash).show(); 
      }, 
      function() {} // Because the hover method has a mouseout state we need to define too 
     ); 
    }); 

此.js腳本適用於鼠標懸停在錨標籤上。不過,我希望這個函數能夠在整個div上工作。用於懸停Div的jQuery圖像交換

如何更改此部分:.filter(this.hash).show();

這樣:。.filter(這(ID或唯一名稱).show();

謝謝

照顧

回答

0

如果你仍然想使用哈希你。能得到使用此代碼是(假設this是你的格):

var hash = $(this).find('a').get(0).hash; 

如果你想使用有關股利獨特的東西我用的div等於CLAS的ID之前img的sName。

如果你有這個網站:

<div id="container1" class="thumbContainer"></div> 
<div id="imageContainer"> 
    <img src="" alt="" class="container1" /> 
</div> 

你可以使用這樣的事情,(我改變了你的懸停鼠標懸停,因爲你只使用):

$(document).ready(function(){ 
    // Hide all large images except the first one 
    $('#imageContainer img').hide().filter(':first').show(); 
    // Select all thumb links 
    $('.thumbContainer').mouseover(function(event) { 
      // Hide all large images except for the one with the same hash as our thumb link 
      $('#imageContainer img').hide().filter("." + this.id).show(); 
     } 
    ); 
}); 
+0

我想你可能意味着要放一個'#'而不是''。 – KyleFarris 2009-04-21 15:06:53