【问题标题】:how can we display text letter by letter using jquery?我们如何使用 jquery 逐个字母地显示文本?
【发布时间】:2017-03-22 10:36:35
【问题描述】:

  var showText = function (target, message, index, interval) 
  {    
    if (index < message.length) 
    { 
      $(target).append(message[index++]); 
      setTimeout(function () { showText(target, message, index, interval); }, interval); 
    } 
  }
  $(function () 
  { 
    showText(".animate", "College Search Simplified", 0, 100);    
  }); 
<script  src="https://code.jquery.com/jquery-3.2.1.min.js"
  integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
  crossorigin="anonymous"></script>
  
<div class="animate"></div>

在此代码中,文本仅动画一次,即逐个字母。那么,如何使用 jquery 连续重复此文本的字母。

【问题讨论】:

标签: php jquery


【解决方案1】:

var showText = function(target, message, index, interval) {
  if (index < message.length) {
    $(target).append(message[index++]);
    setTimeout(function() {
      showText(target, message, index, interval);
    }, interval);
  } else {
    index = 0;
    $(target).html('');
    showText(target, message, index, interval);
  }
}
$(function() {
  showText(".animate", "College Search Simplified", 0, 100);
});
<script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>

<div class="animate"></div>

上面的工作小提琴

【讨论】:

  • 你能做个小提琴吗
  • @MasivuyeCokile,对不起,不知道该怎么做(我试过但这次失败了,但过一段时间会再试一次,直到成功)。在我的机器上测试了这段代码并且工作正常
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
  • 2016-08-02
  • 1970-01-01
相关资源
最近更新 更多