您好我正在玩维加斯背景脚本,并希望使用“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");
答案 0 :(得分:0)
您可以将大部分内容简化为1个功能:
$('body').bind('vegaswalk',
function(e, bg, step) {
$('#marketingText').text("new dialog title " + (step + 1)).fadeIn(3000);
}
);
答案 1 :(得分: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);
});
答案 2 :(得分: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);
}
);