标点加载“动画”,javascript?

前端之家收集整理的这篇文章主要介绍了标点加载“动画”,javascript?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我寻找一个很好的方法显示一些标点符号加载“动画”.

我想要的是这样的东西

This will display at second 1: "Waiting for your input."
This will display at second 2: "Waiting for your input.."
This will display at second 3: "Waiting for your input..."
This will display at second 4: "Waiting for your input...."
This will display at second 5: "Waiting for your input."
This will display at second 6: "Waiting for your input.."
This will display at second 7: "Waiting for your input..."
This will display at second 8: "Waiting for your input...."

等等.

我围着这个圆点开始,以为我可以用jquery循环遍历,再多一个,然后重新设置为1.但代码很笨拙,所以我想知道你会怎么做?

解决方法

制作一串点的诀窍是使一个稀疏的数组,然后加入所有的元素与所需的字符.
var count = 0;
setInterval(function(){
    count++;
    var dots = new Array(count % 10).join('.');
    document.getElementById('loadingtext').innerHTML = "Waiting for your input." + dots;
  },1000);

这是一个Live demo.

猜你在找的JavaScript相关文章