I'm trying to achieve a cycle through text fadein/fadeout effect with strings on an array. For example, I start with an initial text ("Los Angeles") inside a span tag. I want this text to change from the string "Los Angeles" to "Sacramento" with a fadein animation and a delay in between, which I'm trying to achieve with a timing function. I'm defining an array where I store the strings that I want to cycle through. The problem I'm getting is that I can only get to change the string from the first element of the array to the last one. The elements in between, like San Francisco and Berkeley, get ignored by the for loop. What am I doing wrong? Thanks. Any help is appreciated. Here is what I got so far:
<div id="fly" class="container-fluid section text-center">
<h1 id="intro-txt">Go from <br> <span id="dest1" style="color: #b9b7b7;">Los Angeles</span> to <span id="dest2" style="color: #b9b7b7;">Las Vegas</span> <br> with no hassle.</h1>
<script>
var from = ["San Francisco", "Berkeley", "Place3"];
var to = ["Sacramento", "New Mexico", "Place3"];
var total = from.length;
var index = 0;
$(document).ready(function(){
for(index; index < total; index++){
var fromLoc = from[index];
var toLoc = to[index];
var textScroll = function(){
var start = $("#dest1")
$("#dest1").fadeOut(function() {
$(this).text(fromLoc).fadeIn();
});
$("#dest2").fadeOut(function() {
$(this).text(toLoc).fadeIn();
});
}
setTimeout(textScroll, 2000);
}
});
</script>