Difference between revisions of "Template:Queens Canada/Scripts"

m
m
Line 18: Line 18:
 
const wordTime = 2000;
 
const wordTime = 2000;
 
const changeWordTime = 250;
 
const changeWordTime = 250;
 +
//Call word generator functions
 +
setTimeout(alterDisplayWord,wordTime); //Set the first time delay
 +
updateWord();
 +
 +
function alterDisplayWord(){
 +
    if(stateChange == 0){ //if word is in process of being generated
 +
        displayWord = wordArray[wordIndex].substring(0,displayWord.length + wordIncrement); //Add or delete a letter
 +
        if(wordArray[wordIndex] == displayWord || displayWord.length ==0){ //if word is fully generated or deleted
 +
            stateChange = 1; //let next function call know about the change in state
 +
        }
 +
        setTimeout(alterDisplayWord, changeWordTime); //call function again after a delay
 +
        updateWord();
 +
    }
 +
    else{
 +
        stateChange = 0;
 +
        if(displayWord.length == 0){
 +
            if(wordIndex == wordArray.length - 1)
 +
                wordIndex = 0;
 +
            else
 +
                wordIndex++;
 +
            wordIncrement = 1; //change to the generating word increment
 +
            setTimeout(alterDisplayWord, changeWordTime); //set a short time for the next call of the function
 +
        }
 +
        else{
 +
            wordIncrement = -1;
 +
            setTimeout(alterDisplayWord,wordTime);
 +
        }
 +
    }
 +
}
 +
 +
function updateWord(){
 +
    document.getElementById("Changing-Text").innerHTML = displayWord;
 +
}
  
  
Line 125: Line 158:
 
}
 
}
  
//Call word generator functions
 
setTimeout(alterDisplayWord,wordTime); //Set the first time delay
 
updateWord();
 
  
function alterDisplayWord(){
 
    if(stateChange == 0){ //if word is in process of being generated
 
        displayWord = wordArray[wordIndex].substring(0,displayWord.length + wordIncrement); //Add or delete a letter
 
        if(wordArray[wordIndex] == displayWord || displayWord.length ==0){ //if word is fully generated or deleted
 
            stateChange = 1; //let next function call know about the change in state
 
        }
 
        setTimeout(alterDisplayWord, changeWordTime); //call function again after a delay
 
        updateWord();
 
    }
 
    else{
 
        stateChange = 0;
 
        if(displayWord.length == 0){
 
            if(wordIndex == wordArray.length - 1)
 
                wordIndex = 0;
 
            else
 
                wordIndex++;
 
            wordIncrement = 1; //change to the generating word increment
 
            setTimeout(alterDisplayWord, changeWordTime); //set a short time for the next call of the function
 
        }
 
        else{
 
            wordIncrement = -1;
 
            setTimeout(alterDisplayWord,wordTime);
 
        }
 
    }
 
}
 
  
function updateWord(){
+
 
    document.getElementById("Changing-Text").innerHTML = displayWord;
+
}
+
  
 
</script>
 
</script>
 
</html>
 
</html>

Revision as of 15:55, 10 July 2020