m |
Lianaevans (Talk | contribs) m |
||
Line 11: | Line 11: | ||
var foodItems = document.getElementsByClassName("food-item-inner"); | var foodItems = document.getElementsByClassName("food-item-inner"); | ||
var navBtn = document.getElementById("nav-icon"); | var navBtn = document.getElementById("nav-icon"); | ||
+ | var wordArray = ["Humans", "Scientists", "Researchers", "Engineers", "Designers"] | ||
+ | var wordIndex = 0; //Start at first word in wordArray | ||
+ | var displayWord = wordArray[wordIndex]; | ||
+ | var stateChange = 0; | ||
+ | var wordIncrement = -1 //controls whether the word is being generated or deleted | ||
+ | const wordTime = 2000; | ||
+ | const changeWordTime = 250; | ||
+ | |||
$(document).ready(function(){ | $(document).ready(function(){ | ||
Line 117: | Line 125: | ||
} | } | ||
− | // | + | //Call word generator functions |
− | + | setTimeout(alterDisplayWord,wordTime); //Set the first time delay | |
− | + | updateWord(); | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
function alterDisplayWord(){ | function alterDisplayWord(){ | ||
− | if(stateChange == 0){ // if | + | if(stateChange == 0){ //if word is in process of being generated |
− | + | displayWord = wordArray[wordIndex].substring(0,displayWord.length + wordIncrement); //Add or delete a letter | |
− | displayWord = wordArray[wordIndex].substring(0,displayWord.length+wordIncrement); // | + | 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 | |
− | + | ||
− | stateChange = 1; // let | + | |
} | } | ||
− | + | setTimeout(alterDisplayWord, changeWordTime); //call function again after a delay | |
− | setTimeout(alterDisplayWord,changeWordTime);// call | + | |
updateWord(); | updateWord(); | ||
} | } | ||
− | else{ | + | else{ |
− | + | stateChange = 0; | |
− | + | if(displayWord.length == 0){ | |
− | + | if(wordIndex == wordArray.length - 1) | |
− | + | wordIndex = 0; | |
− | + | ||
− | + | ||
− | if(wordIndex == wordArray.length-1) | + | |
− | + | ||
else | else | ||
wordIndex++; | wordIndex++; | ||
− | + | wordIncrement = 1; //change to the generating word increment | |
− | wordIncrement = 1; // change to the generating word increment | + | setTimeout(alterDisplayWord, changeWordTime); //set a short time for the next call of the function |
− | setTimeout(alterDisplayWord,changeWordTime); // set a short time for the next call of the function | + | } |
− | + | else{ | |
− | + | wordIncrement = -1; | |
− | else{ | + | setTimeout(alterDisplayWord,wordTime); |
− | + | } | |
− | + | ||
− | setTimeout(alterDisplayWord,wordTime); | + | |
− | + | ||
− | + | ||
} | } | ||
} | } | ||
function updateWord(){ | function updateWord(){ | ||
− | |||
document.getElementById("Changing-Text").innerHTML = displayWord; | document.getElementById("Changing-Text").innerHTML = displayWord; | ||
− | |||
} | } | ||
</script> | </script> | ||
</html> | </html> |
Revision as of 15:53, 10 July 2020