I have an array of words which I would like to fade-out and fade-in continuously. I am very new to JS and I am not able to figure out.
My code is as below:
animate_loop = function(){
var showText = ["Security","Mobile/Wireless","Cloud/Database","PC/Storage"]
$.each(showText, function(i, val) {
setTimeout(function() {
$('#animate').fadeOut("slow", function() {
$(this).text(val).fadeIn("slow");
});
}, i * 3000);
});
setInterval(function(){animate_loop();},5000)
With this code, the function loops through the array showText
really fast and I was wondering if there is any other approach without a setInterval
to achieve this. May be by just calling animate_loop
function infinitely which I read is not advisable. So any suggestions are welcome.