2015-07-21 49 views
-1

我對JavaScript相當陌生,但在整個前端開發方面有過先前的經驗。我試圖讓JS遍歷提供的列表並在我的網站上顯示結果。每個項目將顯示一次,然後移至列表中的下一個項目。到達最後時,最後一個項目將被永久顯示。我正在使用Textillate JS庫。我提供的JavaScript有什麼特別的錯誤?

我的代碼有什麼問題?

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

<script> 
var title-transitions = [ 
    "Create Solutions", 
    "Build Relationships", 
    "Design Brands", 
    "Redifine Excellence" 
    ], 

    transitionCounter = 0, 
    looped = false, 
    textillateSettings ={ 
     loop:false, 
     in:{ 
     callback:fucntion(){ 
      if(!looped) $('h1.introduction-heading').fadeOut(3800); 
     } 
     } 
    }; 

var $h1 = $('h1.introduction-heading'); 
$h1.introduction-heading(textillateSettings); 

var animationHero = set Interval(function(){ 
    transitionCounter = 
    (transitionCounter == transition.legnth -1) 
    ? 0 : transitionCounter + 1; 

    if(transitionCounter == 0){ 
    looped = true; 
    clearInterval(animatedHero); 
    } 

    $('h1.introduction-heading').remove(); 
    $('h1.introduction-heading') 
    .text(transition[transitionCounter]) 
    .textillate(textillateSettings); 

}, 6000); 
</script> 

這裏是textillate site的網址,如果它可以有任何幫助的話。

+7

如何縮進? – DavidG

+3

打開瀏覽器的JavaScript控制檯。你會在那裏看到錯誤消息。你有一些語法錯誤。 – JJJ

+4

JavaScript變量名稱中不允許使用[Dashes](http://stackoverflow.com/questions/5516106/are-dashes-allowed-in-javascript-variable-names)。 – showdev

回答

0

這段代碼有很多問題,但我只會首先回答那些明顯的破壞語法的問題,一旦你解決了這些問題,也許你可以再去一次。

callback: fucntion(){ 
    if(!looped) $('h1.introduction-heading').fadeOut(3800); 
} 

^拼錯 '功能' 的

$h1.introduction-heading(textillateSettings); 

^這是什麼?您選擇的類名的元素,如果你想申請textillate一些文本這將是

$h1 = $('.introduction-heading'); 

$h1.textillate(textillateSettings); 

然後最後:

var animationHero = set Interval(function(){ 

要調用的方法是setInterval爲一體word

希望這些明顯的問題能讓您更接近解決方案。儘量小心清理語法。 :)

相關問題