2011-07-29 11 views
2

我喜歡在這裏使用這個簡單的代碼簡單的jQuery機場文字效果,需要停止,清除飛行中的變化?

http://www.unwrongest.com/projects/airport/

,這將是爲全天候顯示我的網頁上使用 http://www.xaluan.com

的理念是:溫度會從00跳到到目前的溫度,它看起來不錯,生活.. 問題是,當我從C更改溫度到F,或更改Temp的位置,臨時將需要更改,然後文本效果需要更改飛行。

但我已經嘗試很多時間甚至使用.stop或.clearQue重新啓動效果,但不成功。 它搞亂了,有些情況下不運行,某些情況下的效果陣列成爲組合兩個陣列..我完全以丟了,感謝所有adivices

this is narrow simple code for statup test: 
<span id="tempnow" class="tempnow">30</span> 
<span onclick="changeC()">°F</span> 
<span onclick="changeF()">°C</span> 

<script> 
// fist time run will be: 

    $(function($){ 
$('#tempnow').airport(['00','34']); 
}); 

function changeF() { 
$('#tempnow').airport([ '00', '91' ]); 
} 
function changeC() { 
$('#tempnow').airport([ '00', '34' ]); 
} 

(function($){ 
    $.fn.extend({ 
     airport: function(array) { 

      var self = $(this); 
      var chars = ['0','9','8','7','6','5','4','3','2','1','-']; 
      var longest = 0; 
      var items = items2 = array.length; 

      function pad(a,b) { return a + new Array(b - a.length + 1).join(' '); } 

      $(this).empty(); 

      while(items--) 
       if(array[items].length > longest) longest = array[items].length; 

      while(items2--) 
       array[items2] = pad(array[items2],longest); 

      spans = longest; 
      while(spans--) 
       $(this).prepend("<span class='c" + spans + "'></span>"); 


      function testChar(a,b,c,d){ 
       if(c >= array.length) 
        setTimeout(function() { testChar(0,0,0,0); }, 1000);     
       else if(d >= longest) 
        setTimeout(function() { testChar(0,0,c+1,0); }, 1000); 
       else { 
        $(self).find('.c'+a).html((chars[b]==" ")?"&nbsp;":chars[b]); 
        setTimeout(function() { 
         if(b > chars.length) 
          testChar(a+1,0,c,d+1); 
         else if(chars[b] != array[c].substring(d,d+1).toLowerCase()) 
          testChar(a,b+1,c,d); 
         else 
          testChar(a+1,0,c,d+1); 
        }, 20); 
       } 
      } 

      testChar(0,0,0,0); 
     } 
    }); 
})(jQuery); 



</script> 

我把jsbin這裏希望有人能幫助我通過代碼

http://jsbin.com/onaqis/7/edit#source 

感謝..

+0

目前調用testChar()方法直到永恆。這是原始代碼還是您修改了插件? – polarblau

+0

這是起源腳本..和很受歡迎:可以在http://www.unwrongest.com/projects/airport/下載... ... 如果它叫不停..功能可能需要修改..但我有發電子郵件給業主,沒有任何答覆..希望有人在這裏可以幫助! – binh

回答

0

這裏有一個hackish的解決方法:http://jsfiddle.net/EUKuS/ 您需要採取以下行要打破無休止的循環:

if(c >= array.length) 
    setTimeout(function() { testChar(0,0,0,0); }, 1000);  // <----- COMMENT OUT! 
else if(d >= longest) 

應該可以工作但修復插件會更好。

+0

謝謝你的回答,但沒有無限循環動畫沒有意義..那爲什麼我需要的mod有助於改變它的飛行數組,或停止腳本,然後把新的數組,類似像重新啓動新值.. – binh