Javascript 如何在vegaswalk背景库中淡入文本

Javascript 如何在vegaswalk背景库中淡入文本,javascript,jquery,Javascript,Jquery,您好,我正在玩维加斯的背景脚本,希望使用“vegaswalk”功能为每个背景添加一个标题。一切正常,但我想在div id=“marketingText”上添加一个fadeIn,是否可能?文本每次都需要淡入 $('body').bind('vegaswalk', function(e, bg, step) { if(step == 0) { $('#marketingText').text("new dialog title 1"); } i

您好,我正在玩维加斯的背景脚本,希望使用“vegaswalk”功能为每个背景添加一个标题。一切正常,但我想在div id=“marketingText”上添加一个fadeIn,是否可能?文本每次都需要淡入

  $('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");

您可以将其中的大部分简化为一个函数:

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

  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);
  });
谢谢@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);
  }
);

请告诉我们你尝试了什么,并让我们知道具体出了什么问题。在做任何事情之前!!!执行此操作:$(“#marketingText”).text(“新对话框标题”+(步骤+1));“新建对话框标题”部分将每次更改为,而不是不起作用的if语句,目前仅在此处作为示例。您尝试的代码出了什么问题?似乎有效:谢谢,但请参见上面的内容,因为每个步骤的文本都会发生变化。不要以这种方式构建数组。。。简单地使用
var arr=[“a”、“b”、“c”]
,如果您关心性能,也可以将元素
$(“#marketingText”)
缓存到变量中