如何在每次字符串迭代后调用回调函数?

我正在使用jQuery库类型 – 它在这里找到: http ://macarthur.me/typeit/docs/

这是我的代码

$('.type-it').typeIt({ strings: ['Text 1','Text 2'], speed: 110, breakLines: false, callback: function() { $('.type-it').css('background-color', '#EFC137').delay(1000).queue(function() {$('.type-it').empty() }) } }) .tiPause(1000); 

我想要做的是在键入每个字符串后运行回调函数,而不是在键入所有字符串之后。

有任何想法吗?

提前致谢。

如果库不支持它,我们可以将单个字符串传递给函数。 这是一个黑客做到这一点。

 $(document).ready(function() { var ara = ['Text 1', 'Text 2'].reverse(); doType(); function doType() { var x = ara.pop(); $('.type-it').typeIt({ strings: [x], speed: 110, breakLines: false, callback: function() { $('.type-it').css('background-color', '#EFC137').delay(2000).queue(function() { $('.type-it').empty(); $('.type-it').css('background-color', 'transparent'); if (ara.length > 0) doType(); }) } }); } }); 
 .type-it { transition: all 0.5s ease-in-out; }