Skip to content

Instantly share code, notes, and snippets.

@SaraSoueidan
Created June 8, 2013 02:17
Show Gist options
  • Save SaraSoueidan/5733661 to your computer and use it in GitHub Desktop.
Save SaraSoueidan/5733661 to your computer and use it in GitHub Desktop.
Typing + Highlighting Animation (Demo: Typewriter and highlighter effects with CSS3 transitions: http://jsbin.com/ogevob/1/edit)
$.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
$('p').animateText(15, 'foo');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment