Skip to main content
added 20 characters in body
Source Link
Kyle Macey
  • 50
  • 1
  • 10

Pull it out to a function?

$.fn.textFadeSwap = function(newText, body, customColor="#000"customColor) {
    var transparentColor =$this= $(this), 
        transparentColor = $this.css('background-color') || 'transparent',
    var    originalColor = $(this)$this.css('color') || '#000';'#000',
        customColor = customColor || '#000';

    $(this)$this.animate({ color: originalColor, 500, function(){              
        $(this)$this.text(newText)
            .animate({ color: transparentColor},500, function(){
                    $(this)$this.delay('1000')
                        .animate({ color: originalColor},500, function(){
                            $(this).text(body)
                                .animate({ color: customColor},500)
                                   .focus()
                                      .putCursorAtEnd();
                            });
            });
    });                 
}


if (replyto == body) {
    $('textarea').textFadeSwap("Please enter your reply here", body, '#a7a7a7')
}

Pull it out to a function?

$.fn.textFadeSwap = function(newText, body, customColor="#000") {
    var transparentColor = $(this).css('background-color') || 'transparent'
    var originalColor = $(this).css('color') || '#000';
    
    $(this).animate({ color: originalColor, 500, function(){              
        $(this).text(newText)
            .animate({ color: transparentColor},500, function(){
                    $(this).delay('1000')
                        .animate({ color: originalColor},500, function(){
                            $(this).text(body)
                                .animate({ color: customColor},500)
                                   .focus()
                                      .putCursorAtEnd();
                            });
            });
    });                 
}


if (replyto == body) {
    $('textarea').textFadeSwap("Please enter your reply here", body, '#a7a7a7')
}

Pull it out to a function?

$.fn.textFadeSwap = function(newText, body, customColor) {
    var $this= $(this), 
        transparentColor = $this.css('background-color') || 'transparent',
        originalColor = $this.css('color') || '#000',
        customColor = customColor || '#000';

    $this.animate({ color: originalColor, 500, function(){              
        $this.text(newText)
            .animate({ color: transparentColor},500, function(){
                $this.delay('1000')
                    .animate({ color: originalColor},500, function(){
                        $(this).text(body)
                            .animate({ color: customColor},500)
                               .focus()
                                  .putCursorAtEnd();
                        });
            });
    });                 
}


if (replyto == body) {
    $('textarea').textFadeSwap("Please enter your reply here", body, '#a7a7a7')
}
Source Link
Kyle Macey
  • 50
  • 1
  • 10

Pull it out to a function?

$.fn.textFadeSwap = function(newText, body, customColor="#000") {
    var transparentColor = $(this).css('background-color') || 'transparent'
    var originalColor = $(this).css('color') || '#000';
    
    $(this).animate({ color: originalColor, 500, function(){              
        $(this).text(newText)
            .animate({ color: transparentColor},500, function(){
                    $(this).delay('1000')
                        .animate({ color: originalColor},500, function(){
                            $(this).text(body)
                                .animate({ color: customColor},500)
                                   .focus()
                                      .putCursorAtEnd();
                            });
            });
    });                 
}


if (replyto == body) {
    $('textarea').textFadeSwap("Please enter your reply here", body, '#a7a7a7')
}