Punctuation loading “animation”, javascript?

后端 未结 8 2341
生来不讨喜
生来不讨喜 2021-02-19 17:54

I\'m looking for a good way to display some punctuation loading \"animation\".

What I want is something like this:

This will display at second 1: \"Waiti         


        
8条回答
  •  滥情空心
    2021-02-19 18:27

    The trick to making a string of dots is to make a sparse Array and then join all the elements with the desired character.

    var count = 0;
    setInterval(function(){
        count++;
        var dots = new Array(count % 10).join('.');
        document.getElementById('loadingtext').innerHTML = "Waiting for your input." + dots;
      }, 1000);
    

    Here is a Live demo.

提交回复
热议问题