Reputation: 100
I've decided to update all my jquery to work with jquery 1.9.1 but I can find out why this script has stopped working. Works fine in all other jquery versions.
// Typewriter function
$.fn.Typewriter = function Typewriter(opts) {
var $this = this,
defaults = {
animDelay: 50
},
settings = $.extend(defaults, opts);
var objDiv = document.getElementById(settings.div);
$.each(settings.text, function (i, letter) {
setTimeout(function () {
$this.html($this.html() + (letter != '\n' ? letter : '<br />'));
objDiv.scrollTop = objDiv.scrollHeight;
}, settings.animDelay * i);
});
};
// Call with
// $('#divID').Typewriter({animDelay: 10,text: 'text to animate', div: 'divID'});
$('#outputDiv').Typewriter({
animDelay: 10,
text: 'Why does this not work in jquery 1.9.1? :( ',
div: 'outputDiv'
});
Js fiddle included below
EDIT:
Using the chrome development tool I get a error in the console reading:
Uncaught TypeError: Cannot use 'in' operator to search for '42' in Why does this not work in jquery 1.9.1? :(
Upvotes: 2
Views: 636
Reputation: 664538
One does not use $.each
to loop over strings. I doubt it worked properly before. For a quick fix, change it to settings.text.split('')
.
Btw, appending to innerHTML
can be troublesome. Better use the DOM, see here for that callback hell wrapped in a jQuery plugin :-)
Upvotes: 6