我正在做一个 jquery 类型的写作效果,并在打字文本 jquery 动画完成后运行一个函数
我如何检测到最后一条消息已打印并执行诸如警报之类的功能
这是我的代码 http://jsfiddle.net/dnkwp/28/
var where, when, iteration; //added
iteration = 0;
bigDelay = 0;
$.fn.teletype = function (opts) {
iteration++;
var $this = this,
defaults = {
animDelay: 50
}, settings = $.extend(defaults, opts);
var letters = settings.text.length; //added
where = '#' + $($this).attr('id'); //added
when = settings.animDelay; //added
if (iteration > 1) {
bigDelay = bigDelay + settings.text.length * settings.animDelay;
setTimeout(function () {
$.each(settings.text, function (i, letter) {
setTimeout(function () {
$this.html($this.html() + letter);
}, settings.animDelay * i);
});
}, bigDelay);
} else {
$.each(settings.text, function (i, letter) {
setTimeout(function () {
$this.html($this.html() + letter);
}, settings.animDelay * i);
//alert($('#container4').html().length);
});
}
};
$(function () {
$('#container1').teletype({
animDelay: 100,
text: 'This is message 1'
});
$('#container2').teletype({
animDelay: 100,
text: 'this is message 2'
});
$('#container3').teletype({
animDelay: 100,
text: 'this is message 3'
});
$('#container4').teletype({
animDelay: 100,
text: 'this is message 4'
});
});
if ($('#container4').html().length == 17) {
alert("test")
} //this not work with me