我寻找一个很好的方法来显示一些标点符号加载“动画”.
我想要的是这样的东西
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.