2009-09-08 45 views
1

所以我寫了這麼一小段代碼來嘗試一些用於預加載的圖像交換的新方法,並且我遇到了一些麻煩。Jquery Mouseenter/Mouse圖片交換

我的問題是,我對此有一些填充和文本圖像的容器,但我的側翻激活只有當有人滾動,而不是容器在圖像上發生。我必須有一些小錯,希望有人能幫助我。仍在學習!

下面是HTML:

<div class="projectThumb"> 
    <img src="/img/aeffect_button_static.gif" width="146" height="199" class="static" name="aeffect" alt="" />   
    <img src="/img/aeffect_button_rollover.jpg" width="146" height="199" class="rollover" name="aeffect" alt="" /> 
    <p class="title">A.EFFECT: Film Poster</p> 
</div> 

這裏是jQuery的:

$(document).ready(function(){ 
    $(".rollover").hide(); 
$(".projectThumb").mouseenter(
     function(){ 
      $(this).attr(".static").hide(); 
     }, 
     function(){ 
      $(this).attr(".rollover").show(); 
     }); 
$(".projectThumb").mouseleave(
     function(){ 
      $(this).attr(".rollover").hide(); 
     }, 
     function(){ 
      $(this).attr(".static").show(); 
     }); 
}); 

回答

4

我認爲你正在尋找hover

$(document).ready(function(){ 
    $(".rollover").hide(); 
    $(".projectThumb").hover(
    function(){ 
     $(this).find(".static,.rollover").toggle(); 
    }, 
    function(){ 
     $(this).find(".static,.rollover").toggle(); 
    }); 
}); 

雙方的mouseenter和鼠標離開只取一個參數,但是你定義了兩個回調函數。

0

爲什麼不嘗試:

$(".projectThumb").bind("mouseenter mouseleave", function(e) { 
    $(this).toggle(); 
});