Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a sentence, one character at a time

Tags:

jquery

I want to display a sentence one character at a time, one by one, with jQuery. Is there a plugin that can do this Or how could I get this effect?

like image 337
dreamchaser Avatar asked Nov 08 '11 16:11

dreamchaser


2 Answers

You could write a little plugin to do it. Here's something to get you started (far from perfect, just to give you an idea!):

(function($) {
    $.fn.writeText = function(content) {
        var contentArray = content.split(""),
            current = 0,
            elem = this;
        setInterval(function() {
            if(current < contentArray.length) {
                elem.text(elem.text() + contentArray[current++]);
            }
        }, 100);
    };

})(jQuery);

You can call that like this:

$("#element").writeText("This is some text");

Here's a working example.

like image 165
James Allardice Avatar answered Sep 25 '22 15:09

James Allardice


Have a look at the TickerType plugin: http://www.hungry-media.com/code/jQuery/tickerType/

like image 35
Rory McCrossan Avatar answered Sep 22 '22 15:09

Rory McCrossan