我们如何使用jquery逐字母显示文本?

时间:2017-03-22 10:36:36

标签: php jquery



import os

path = 'C:\\Users\\user\\My_Test_Traces\\1000_Traces_npy'
file_names = os.listdir(path)

for file in file_names:

    start = file[0:file.index("Trace=")+6]
    end = file[file.index("_key"):]
    num = file[len(start): file.index(end)]

    new_name = start + str(100000+int(num)) + end

    os.rename(os.path.join(path, file), os.path.join(path, new_name))

  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);    
  }); 
&#13;
&#13;
&#13;

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

1 个答案:

答案 0 :(得分: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>

上面的小提琴