A very simple "loading ..." animation in 5 lines of JavaScript
Here's a way to do a really simple "loading ..." animation, in just 5 lines of JavaScript
i = 0;
setInterval(function() {
i = ++i % 4;
$("#loading").html("Loading "+Array(i+1).join("."));
}, 800);
Working JavaScript Demo on codepen.io
For the lazy, who don't want to go over to codepen.io and see the actual working JavaScript demo. Here's an animated gif that will give you an idea of what it looks like.

Written by James Barnett
Related protips
2 Responses
Hello James,
this is as simple as really nice and useful.
I would like to use it in my site, and display it meanwhile the page is loading, but I don't really know how to do that :O
Could you please give me an hand?
Cheers, MT
Well that is very nice.
I made minor changes to make it pure JS and actually added some style to it.
http://codepen.io/dvLden/pen/uHBpe/
Regards,
Nenad - dvLden
Have a fresh tip? Share with Coderwall community!
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside