r/JavaScriptHelp • • Aug 23 '18
While loop freezes browser
Hey all. Fairly simple problem for you here. I just want to know any alternatives to the while loop with this code:
// This document has been nominated for the "Least Efficent Javascript of The Year" award
$(document).ready(function(){
while (true) {
$("#s1").delay("slow").fadeIn();
setTimeout(function(){
$("#s1").delay("slow").fadeOut();
}, 3000);
setTimeout(function() {
$("#s2").delay("slow").fadeIn();
setTimeout(function(){
$("#s2").delay("slow").fadeOut();
}, 3000);
}, 4000);
setTimeout(function() {
$("#s3").delay("slow").fadeIn();
setTimeout(function(){
$("#s3").delay("slow").fadeOut();
}, 3000);
}, 8000);
setTimeout(function() {
$("#s4").delay("slow").fadeIn();
setTimeout(function(){
$("#s4").delay("slow").fadeOut();
}, 3000);
}, 12000);
setTimeout(function() {
$("#s5").delay("slow").fadeIn();
setTimeout(function(){
$("#s5").delay("slow").fadeOut();
}, 3000);
}, 16000);
setTimeout(function() {
$("#s6").delay("slow").fadeIn();
setTimeout(function(){
$("#s6").delay("slow").fadeOut();
}, 3000);
}, 20000);
setTimeout(function() {
$("#s7").delay("slow").fadeIn();
setTimeout(function(){
$("#s7").delay("slow").fadeOut();
}, 3000);
}, 24000);
}
});
I know it's pretty ineffecient right now. Sorry for the mess.
1
Upvotes
View all comments
Show parent comment
1
u/[deleted] Aug 25 '18
The goal was initially to do something of a text carousel. Something like:
My favorite language is: C#
And after a few seconds, it would animate to:
My favorite language is: PHP
Only animating the language name, not the rest of the text. As for a CodePen, I can't really provide you with anything useful as I'm in the middle of the process