setTimeout Jquery help
how can i settimeOut of 1 sec, for the following animation to take place, i tried using SetTimeout, but it didnt work, heres the code
$(document).ready(f开发者_开发百科unction(){
$('.caption_logo .flying-text').css({opacity:0});
$('.caption_logo .active-text').animate({opacity:1, marginLeft: "-350px"}, 500);
var intval = setInterval(changeText, 300);
function changeText(){
var $activeText = $(".caption_logo .active-text");
var $nextText = $activeText.next();
if($activeText.next().length == 0) clearInterval(intval);
$nextText.css({opacity: 0}).addClass('active-text').animate({opacity:1, marginLeft: "-350px"}, 500, function(){
$activeText.removeClass('active-text');
});
}
});
Can you try with setTimeout function like below:
$(document).ready(function(){
$('.caption_logo .flying-text').css({opacity:0});
$('.caption_logo .active-text').animate({opacity:1, marginLeft: "-350px"}, 500);
setTimeout(changeText, 300);
function changeText(){
var $activeText = $(".caption_logo .active-text");
var $nextText = $activeText.next();
if($activeText.next().length > 0) setTimeout(changeText, 300);
$nextText.css({opacity: 0}).addClass('active-text').animate(
{
opacity:1,
marginLeft: "-350px"
},
500,
function(){
$activeText.removeClass('active-text');
}
);
}
});
Hope it work for you.
精彩评论