Joe Lanman

Web design and development when not playing computer games

IE Bug: Fading animation makes text render without anti-aliasing

Published on December 1, 2009

Affects: IE6, IE7

Description

When using jQuery to fade elements, Internet Explorer will remove anti-aliasing from text (causing it to appear pixelated) .

Workaround

Remove the ‘filter’ attribute used by IE to fade elements once the fade is complete (view the full post to read the code)

Code based on GBegen’s comment on Stack Overflow

http://stackoverflow.com/questions/778208/jquery-fadein-leaves-text-not-anti-aliased-in-ie7

(function($) {
    $.fn.fadeIn = function(speed, callback) {
        return this.animate({opacity: 'show'}, speed, function() {
                if ( $.browser.msie )
                {
                       this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
		callback.call(this);
                }
        });
    };

    $.fn.fadeOut = function(speed, callback) {
        return this.animate({opacity: 'hide'}, speed, function() {
                if ( $.browser.msie )
                {
                      this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
		callback.call(this);
                }
        });
    };

    $.fn.fadeTo = function(speed, to, callback) {
        return this.animate({opacity: to}, speed, function() {
                if ( to == 1 && $.browser.msie )
                {
                     this.style.removeAttribute('filter');
                }
                if ( $.isFunction(callback) )
                {
	         callback.call(this);
	     }
        });
    };
})(jQuery);

Filed under: IE Bugs
Tags: , ,

5 Comments

  1. Daniel says:

    Great drop in solution. Just a comment, the code has an error: in the fadeTo function, the first condition is supposed to have a couple of ampersands to signify logical AND instead of the escaped html code.

    Thanks for this!

  2. Joe Lanman says:

    Sorry – I missed your comment for a while – thanks for the fix!

  3. [...] Unfortunately this means you have to deal with the IE6/7 text anti-alias bug – workaround here [...]

  4. Mark Iliff says:

    Smashing. Works a treat. Thanks very much for sharing.

    BTW you say “Affects: IE6, IE7″. My client has IE8 and says that it suffers from the same problem.

    ยต

Leave a Reply

WP SlimStat

Asynchronous Google Analytics for WordPress plugin powered by WordPress Expert at minilibra.com.