2014-10-30 40 views
1

你好我玩的拉斯維加斯背景劇本,並想使用「vegaswalk」功能爲每個背景添加標題。所有工作正常,但我想在div id =「marketingText」上添加fadeIn,這可能嗎?文字每次都需要淡入淡出。如何淡入在vegaswalk背景畫廊中的文字

$('body').bind('vegaswalk', 
    function(e, bg, step) { 
    if(step == 0) { 
     $('#marketingText').text("new dialog title 1"); 
     } 
    if(step == 1) { 
     $('#marketingText').text("new dialog title some different text 2"); 
     } 
    if(step == 2) { 
     $('#marketingText').text("new dialog title more text 3"); 
     } 
    if(step == 3) { 
     $('#marketingText').text("new dialog title and some more 4"); 
     } 
    } 
); 

我試過以下

$('#marketingText').hide().fadeIn(3000).text("new dialog title 4"); 
+0

請告訴我們你已經嘗試了什麼,讓我們知道具體是什麼出了問題。 – showdev 2014-10-30 23:23:37

+0

在什麼之前!這樣做:$('#marketingText')。text(「new dialog title」+(step + 1));而不是如果語句 – Daniel 2014-10-30 23:25:02

+0

不起作用,因爲「新對話標題」部分每次都會改變,目前僅以此爲例 – gareth 2014-10-30 23:29:02

回答

0

嘗試,如:

var $mark= $('#marketingText'); 
    var textsArr = [ // Array of texts 
    "new dialog title 1", 
    "new dialog title some different text 2", 
    "new dialog title more text 3", 
    "new dialog title and some more 4" 
    ]; 

    $('body').bind('vegaswalk', function(e, bg, step) { 
    $mark.hide().text(textsArr[step]).fadeIn(1000); 
    }); 
+0

謝謝,我最終到達那裏:) – gareth 2014-10-30 23:39:03

+0

@ gareth不客氣;) – 2014-10-30 23:39:35

0

可以簡化這個最成1個功能:

$('body').bind('vegaswalk', 
    function(e, bg, step) { 
     $('#marketingText').text("new dialog title " + (step + 1)).fadeIn(3000); 
    } 
); 
+0

應該是步驟+ 1. – Daniel 2014-10-30 23:29:04

+0

@丹尼爾 - 是的,只是做了一個編輯,thx! – tymeJV 2014-10-30 23:29:30

+0

謝謝,但請參閱上文,因爲文本會改變每一步以及 – gareth 2014-10-30 23:30:47

0

感謝@tymeJV

使用方法和添加陣列工作

var myArray = []; 
myArray[ 0 ] = "new dialog title 1"; 
myArray[ 1 ] = "new dialog title 2"; 
myArray[ 2 ] = "new dialog title 3"; 
myArray[ 3 ] = "new dialog title 4"; 


$('body').bind('vegaswalk', 
    function(e, bg, step) { 
    $('#marketingText').text(myArray[ step ]).hide().fadeIn(3000); 
    } 
); 
+0

不要像這樣構建數組... ...使用簡單的'var arr = [「a」,「b」,「c」]',另外,如果您關心性能,則將元素$('#marketingText')'緩存到變量 – 2014-10-30 23:40:35