I have a setInterval function that changes an elements innerHTML from an array, every half a second. I would like to show the fifth item for 5 seconds, but then resume the setInterval at every half a second.
I tried changing the speed during the setInterval:
if (wordsCnt==5) {
speed = 5000
}else{
speed = 500
}
var speed = 500
var cycleWords = document.getElementById("cycle-words");
var wordsCnt = 0;
var words = [
"Graphic designers",
"Founders",
"Photographers",
"Copywriters",
"Audio designers",
"Startups",
"Film makers",
"Architects",
"Instagramers"
];
window.setInterval(function() {
cycleWords.innerHTML = words[wordsCnt];
if (wordsCnt < words.length-1) {
wordsCnt++;
} else {
wordsCnt = 0;
}
if (wordsCnt==5) {
speed = 5000
}else{
speed = 500
}
}, speed);
<div id="">
Working with <span id="cycle-words">Copy writers</span></div>
</div>
The speed remains the same.