Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery text loading animation

Trying to make a text ... loading animation

here's where I stand: http://jsfiddle.net/aGfct/

I can get the ... to be added at 500 ms intervals, but then I want to remove them and then start the animation over / until loading is done (basically it can loop forever, and I will fade it out when done).

Any help would be great.

Thanks.

_charlie

like image 771
stursby Avatar asked Dec 16 '11 16:12

stursby


People also ask

How can I create a please wait loading animation using jQuery?

on({ ajaxStart: function() { $body. addClass("loading"); }, ajaxStop: function() { $body. removeClass("loading"); } }); That's it!

How do I load a GIF while page is loading?

Using Code Step 1: Add loader DIV tag inside body tag. This DIV helps to display the message. Step 2: Add following CSS how it is going to displaying in browser. Step 3: Add following jQuery code when to fadeout loading image when page loads.

What is the correct syntax of animate () method?

The jQuery animate() method is used to create custom animations. Syntax: $(selector). animate({params},speed,callback);


2 Answers

i = 0;
setInterval(function() {
    i = ++i % 4;
    $("#loading").html("loading"+Array(i+1).join("."));
}, 500);

If you wish to change the string after 5 says, that's after 10 iterations. This can be accomplished like this.

i = 0;
text = "loading";
setInterval(function() {
    $("#loading").html(text+Array((++i % 4)+1).join("."));
    if (i===10) text = "start";
}, 500);
like image 73
kba Avatar answered Sep 27 '22 20:09

kba


http://jsfiddle.net/paska/aGfct/12/

var originalText = $("#loading").text(),
    i  = 0;
setInterval(function() {

    $("#loading").append(".");
    i++;

    if(i == 4)
    {
        $("#loading").html(originalText);
        i = 0;
    }

}, 500);
like image 29
Diego Avatar answered Sep 27 '22 18:09

Diego