2015-01-04 77 views
1

我測試我的網站添加一些jQuery交互。我創造了這個腳本:mouseenter和mouseleave不工作在jquery

$(document).ready(function() { 
    $('.flash').on({ 
     mouseenter: function (
      $('.flash').hide(); 
    }, 
    mouseleave: function { 
     $('.flashOn').show(); 
    } 
}); 

很簡單使閃光燈閃光:http://www.paolobergomi.it/sitob/index.html但實際上我沒有任何線索,爲什麼不工作。我調試了很多,但都是一樣的。 div正確放置在你看到的HTML中,腳本沒問題(我認爲),但它不會工作,任何線索都是值得歡迎的。

回答

4

mouseenter和jQuery的mouseleave做工精細,當你使用正確的語法:

$('.flash').on({ 
    mouseenter: function() { 
     $('.flashOn').hide(); 
    }, 
    mouseleave: function() { 
     $('.flashOn').show(); 
    } 
}); 

Example fiddle

我也假設mouseenter處理程序應隱藏.flashOn元素?

+1

新語法我要在相同的元素多個處理程序,tyvm先生 – sodawillow

+0

我在CSS創建了兩個班,一個顯示無(閃光燈開),基本上當我mouseover我希望包含在第二個div(顯示無)的圖像,它會顯示和隱藏「閃光燈」類。但它無法正常工作。我試過你的,但沒有工作。無論如何感謝 –

+0

嗨,它的工作原理。好吧,對不起,不好解釋。我想第二個圖像重疊,並取代第一,不在旁邊......我需要解決這個問題,但你的確定。謝謝 –

1

對於mouseenter和mouseleave,您有語法錯誤。

$('.flash').on({ 
    mouseenter: function (// here should be(){ 
    $('.flashOn').hide(); 
    }, 
    mouseleave: function { // here should be(){ 
    $('.flashOn').show(); 
    } 
}); 
+0

謝謝,很好。現在,當我寫給安德魯,我得到了正確的語法。我只需要稍微修改一下這兩張圖片就不在旁邊,而是在另一張圖片上。 –

0

最終解決

$('.flash').on ({ 
    mouseenter : function(){ 

    $('.flash').hide(); 
    $('.flashOn').show(); 
}, 
    mouseleave: function (){ 
    $('.flashOn').hide(); 
    $('.flash').show(); 

} 
}); 

感謝正確的語法,是確定現在