Last Updated: February 25, 2016
·
20.33K
· barnettjw

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.

2 Responses
Add your response

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

over 1 year ago ·

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

over 1 year ago ·