$.fn.animateText = function(delay, klass) { | |
var text = this.text(); | |
var letters = text.split(''); | |
return this.each(function(){ | |
var $this = $(this); | |
$this.html(text.replace(/./g, '<span class="letter">$&</span>')); | |
$this.find('span.letter').each(function(i, el){ | |
setTimeout(function(){ $(el).addClass(klass); }, delay * i); | |
}); | |
}); | |
}; |
Usage: | |
Create a class in CSS with some styles and run the plugin on an element that contains some raw text, like a paragraph. | |
$('p').animateText(15, 'foo'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment