标点符号加载“动画",javascript? [英] Punctuation loading "animation", javascript?

查看:45
本文介绍了标点符号加载“动画",javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种显示标点符号加载动画"的好方法.

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

我想要的是这样的:

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...."

等等.

我首先将 spans 中的点包围起来,并认为我可以用 jquery 遍历它们并显示一个,一个,一个,然后重置为 1.但是代码变得非常笨拙,所以我想知道你会怎么做?

I started by surrounding the dots in spans and thought I could loop through them with jquery and display one more, one more, one more, then reset to 1. But the code got very clumsy, so I wonder how you would do this?

推荐答案

制作点串的诀窍是制作一个稀疏数组,然后将所有元素与所需字符连接起来.

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);

这是一个现场演示.

这篇关于标点符号加载“动画",javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆