Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
73
rated 0 times [  78] [ 5]  / answers: 1 / hits: 50662  / 14 Years ago, sun, january 9, 2011, 12:00:00

I wanna create some loading dots, like this:



At 0000 miliseconds the span content is: .



At 0100 miliseconds the span content is: ..



At 0200 miliseconds the span content is: ...



In a loop.



What is the best / easiest way to make it?


More From » css

 Answers
2
<span id=wait>.</span>

<script>
var dots = window.setInterval( function() {
var wait = document.getElementById(wait);
if ( wait.innerHTML.length > 3 )
wait.innerHTML = ;
else
wait.innerHTML += .;
}, 100);
</script>





Or you can get fancy and have them go forward and back:



<span id=wait>.</span>

<script>
window.dotsGoingUp = true;
var dots = window.setInterval( function() {
var wait = document.getElementById(wait);
if ( window.dotsGoingUp )
wait.innerHTML += .;
else {
wait.innerHTML = wait.innerHTML.substring(1, wait.innerHTML.length);
if ( wait.innerHTML === )
window.dotsGoingUp = true;
}
if ( wait.innerHTML.length > 9 )
window.dotsGoingUp = false;



}, 100);
</script>


Or you could make them go back and forth randomly:



<span id=wait>.</span>

<script type=text/javascript>
var dots = window.setInterval( function() {
var wait = document.getElementById(wait);
if ( Math.random() < .7 )
wait.innerHTML += .;
else
wait.innerHTML = wait.innerHTML.substring(1, wait.innerHTML.length);
}, 100);
</script>


Or I could get a life and stop posting additional snippets.... :D



As Ivo said in the comments, you need to clear the interval at some point, especially if you are not loading a new page after the waiting is finished. :D


[#94311] Friday, January 7, 2011, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
naya

Total Points: 60
Total Questions: 87
Total Answers: 87

Location: Guam
Member since Fri, Jun 18, 2021
3 Years ago
;