2013-05-28 30 views
0

我試圖在h1上使用jQuery懸停的背景顏色,因爲IE,但沒有任何反應。我檢查了我的JavaScript來源,這兩個鏈接是正確的。我已經嘗試過其他屬性(高度,頂端...),在其他divs,但沒有發生過。我加入了我認爲相關的代碼部分。有人看到有什麼問題嗎?jQuery的動畫沒有做任何事情

<!DOCTYPE html> 
<html> 
<head> 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script> 
<script type="text/javascript" src="http://localhost/WP-remivincent/wp-content/themes/data.vortex/js/ColorAnimation/jquery.animate-colors-min.js"></script> 

<script> 
     $('.infos-une').hover( 
     function(){ 
      $(this).animate({backgroundColor: 'rgba(190,52,19,0.8)'}); 
     }, 
     function(){} 
    ); 
    </script> 

</head> 

<style>   // In my style.css file 
.infos-une {  // it’s a <h1> 
background-color: rgba(0,0,0,0.6); 
color: #fff; 
display: block; 
height: 130px; 
padding: 20px; 
position: absolute; 
    top: 311px; 
width: 301px; 
} 
</style> 

<section> 
<div class="articles-une-container"> 
<div class="articles-une"> 
<div> 
    <a href="http://localhost/WP-remivincent/article-title/"> 
     <img width="341" height="341" src="illustration.jpg" class="attachment-post-thumbnail wp-post-image" alt="illu-3"> 
     <h1 class="infos-une gd rokkit">Article title</h1> 
    </a> 
</div> 
</div> 
</div> 
</section> 

回答

3

您是否試過在文檔準備好包裝代碼?

$(document).ready(function() { 
    // your code here ... 
}); 

Jquery document ready

+0

這總是可以做到用'$(函數(){/ *代碼* /})短; ' – Biketire

+0

哦,這是尷尬。對不起,我是一個JavaScript和jQuery初學者... 非常感謝,但這一直在竊聽一段時間! – aeon

0

這個腳本標籤是在head

<script> 
    $('.infos-une').hover( 
     function(){ 
      $(this).animate({backgroundColor: 'rgba(190,52,19,0.8)'}); 
     }, 
     function() {} 
    ); 
</script> 

由於當腳本解釋沒有加載body標籤的結果。所以$('.infos-une')不會返回任何節點。你可以嘗試腳本標記移動到文檔的末尾,或包裹腳本$.ready,像

<script> 
    $(document).ready(function() { 
     $('.infos-une').hover( 
      function(){ 
       $(this).animate({backgroundColor: 'rgba(190,52,19,0.8)'}); 
      }, 
      function() {} 
     ); 
    }); 
</script>