View Single Post
Old 11-27-2012, 03:30 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,245
Thanks: 10
Thanked 531 Times in 525 Posts
devnull69 will become famous soon enough
Your problem is a scope switch. So inside the setInterval loop "this" will no longer refer to your jQuery object but rather to the "window" object. A workaround would be to store the reference and use this temporary variable instead of "this" inside setInterval
Code:
(function($){
    $.fn.textAnim = function(text,speed){
        var progress = 0;
        var that = this;
        var a = setInterval(function(){
            progress++;
            $(that).html(text.substring(0,progress));
            if(progress == text.length){
                clearInterval(a);
            }
        },speed);
    };
})(jQuery);
devnull69 is offline   Reply With Quote
Users who have thanked devnull69 for this post:
mrbean (11-27-2012)