Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/414.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 打字效果:每字一个字_Javascript_Jquery_Css - Fatal编程技术网

Javascript 打字效果:每字一个字

Javascript 打字效果:每字一个字,javascript,jquery,css,Javascript,Jquery,Css,我一直在琢磨如何使打字效果达到一个字一个字,而不是一个字母一个字母。到目前为止,我搜索到的所有链接都提供了每封信一台打字机的效果 这有可能实现吗?或者您做过类似的事情吗?创建一个数组,其中包含您希望一次打印一个的单词 const sentence = 'this sentence will be displayed one word at a time'; var arrayOfWords = sentence.split(' '); for (var i = sentence.lengt

我一直在琢磨如何使打字效果达到一个字一个字,而不是一个字母一个字母。到目前为止,我搜索到的所有链接都提供了每封信一台打字机的效果


这有可能实现吗?或者您做过类似的事情吗?

创建一个数组,其中包含您希望一次打印一个的单词

const sentence = 'this sentence will be displayed one word at a time';
var arrayOfWords = sentence.split(' ');

for (var i = sentence.length - 1; i >= 0; i--) {
    setTimeout(function(){
        console.log(sentence[i]); // or display another way
    }, 400) // set this to your desired interval
}
这很容易。 只需注册一个间隔,拆分文本,反转数组并弹出最后一项。然后将其附加到文本容器中。完成了

JS

你觉得这个怎么样


是的,这是可能的。这个问题没有具体的编程相关问题需要我们解决,因此在stackoverflow中它是离题的。请回顾@Esko hm。。。我认为这个问题非常清楚,尽管措辞肯定很糟糕:/可能的重复,也可以创建一个字符串,让函数拆分它。@PatrickMlr是的,你是对的。使用split方法将使其更加方便,而不是手动拆分输入。非常感谢!:他们说这不是一个需要解决的程序。。。但你还是帮了我!我真的很感激@Woppi你甚至改进了代码,这很好。干杯
var myText = "Some text you want to be typed automagically..";
var myWords = myText.split(" ").reverse();

var ntrvl = setInterval(function() {
  addNextWord();
}, 150);

function addNextWord() {
  var nextWord = myWords.pop();
  if(nextWord !== undefined) {
      var textNow = $(".write-here").text() + " " + nextWord;
      $(".write-here").text(textNow);
  }
}