2013-04-14 147 views
0

下面是我使用2個引號淡入淡出的完整HTML代碼。它在jfiddle中工作,但不在我的網頁上。誰能告訴我什麼是錯的?使用CSS和jQuery淡入淡出

這裏的jfiddle:here

和這裏的HTML代碼:

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
    <title>Untitled Document</title> 
    <style> 
    .quotes {display: none;}​ 
    </style> 
    </head> 

    <body> 
    <h2 class="quotes">first quote</h2> 
    <h2 class="quotes">second quote</h2>​ 

    <script> 
    (function() { 

     var quotes = $(".quotes"); 
     var quoteIndex = -1; 

     function showNextQuote() { 
      ++quoteIndex; 
      quotes.eq(quoteIndex % quotes.length) 
       .fadeIn(2000) 
       .delay(2000) 
       .fadeOut(2000, showNextQuote); 
     } 

     showNextQuote(); 

    })();​ 
    </script> 
    </body> 
    </html> 
+0

你能否以更具體的方式提出你的問題。你有什麼嘗試。你認爲這個錯誤在哪裏?你能找到更具體的方法來問我的程序有什麼問題嗎? – sylvanaar

回答

5

地址:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 

在你的頭部或身體標記。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Untitled Document</title> 
<style> 
.quotes {display: none;}​ 
</style> 
</head> 

<body> 
<h2 class="quotes">first quote</h2> 
<h2 class="quotes">second quote</h2>​ 

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> 
<script> 
(function() { 

    var quotes = $(".quotes"); 
    var quoteIndex = -1; 

    function showNextQuote() { 
     ++quoteIndex; 
     quotes.eq(quoteIndex % quotes.length) 
      .fadeIn(2000) 
      .delay(2000) 
      .fadeOut(2000, showNextQuote); 
    } 

    showNextQuote(); 

})(); 
</script> 
</body> 
</html> 
+0

我複製並粘貼完整的代碼,因爲它是由你...它仍然不起作用。我使用的是Mac和瀏覽器Chrome和Safari。這是一個問題嗎? – Arihant

+0

剛剛解決了我的問題,請重試。 :-) –

+0

工作!定時器耗盡時將接受答案。你能告訴我我哪裏出錯了嗎? – Arihant