Created
November 16, 2013 08:08
-
-
Save geminorum/7497412 to your computer and use it in GitHub Desktop.
jQuery Typer, from : http://jsfiddle.net/ARTsinn/RED9H/4/
RTL compatible
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.fn.typer = function(text, options){ | |
options = $.extend({}, { | |
char: ' ', | |
delay: 1000, | |
duration: 600, | |
endless: true | |
}, options || text); | |
text = $.isPlainObject(text) ? options.text : text; | |
var elem = $(this), | |
isTag = false, | |
c = 0; | |
(function typetext(i) { | |
var e = ({string:1, number:1}[typeof text] ? text : text[i]) + options.char, | |
char = e.substr(c++, 1); | |
if( char === '<' ){ isTag = true; } | |
if( char === '>' ){ isTag = false; } | |
elem.html(e.substr(0, c)); | |
if(c <= e.length){ | |
if( isTag ){ | |
typetext(i); | |
} else { | |
setTimeout(typetext, options.duration/10, i); | |
} | |
} else { | |
c = 0; | |
i++; | |
if (i === text.length && !options.endless) { | |
return; | |
} else if (i === text.length) { | |
i = 0; | |
} | |
setTimeout(typetext, options.delay, i); | |
} | |
})(0); | |
}; | |
$('#foo').typer(['<i>فارسی</i> <u>کلام</u> <b>شعر است</b>!', 'Foo bar.', 1337]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment