Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IE is losing ClearType

I'm experiencing something really strange!

I have a div that I'm hiding with JS (jQuery). Like this:

$('#myDiv').hide();

Then when I make a fadeIn like this:

$("#myDiv").fadeIn('slow');

then the text loses ClearType in IE but not in FF. If I go with toggle insted of fadeIn, then it's all fine.

What is IE up to and is there any solutions for it because it looks horrible. (I have ClearType on as you maybe understand at this point)

like image 588
Adis Avatar asked Jan 04 '09 14:01

Adis


People also ask

How do I enable ClearType in Windows 11?

Turn on ClearTypePress the Windows + Q key on the keyboard. In the Search box type ClearType. In the search results list, click Adjust ClearType text (Control panel). Check Turn on ClearType, and click Next.

Does Windows 11 have ClearType?

ClearType is a software technology developed by Microsoft that improves the readability of text on existing LCDs (Liquid Crystal Displays), such as laptop screens, Pocket PC screens, and flat panel monitors.

Do you need ClearType?

ClearType On Generally speaking, ClearType does a fairly good job at sharpening text, particularly on lower resolution displays, but it can also make the edges of a letter look more blurry, somewhat like an anti-aliasing effect, a process that softens jagged edges in games.

Does Windows 10 have ClearType?

Click the Windows 10 Start button, to open the Search box.In the Search field, type Adjust ClearType text. 3. Under the Best Match option, click Adjust ClearType text.


2 Answers

A quick search on the subject shows the following:

jQuery fadeIn/fadeOut IE cleartype glitch

The problem seems to be that the CSS "filter" attribute is not automatically removed. The most simple solution to this problem would be removing it manually:

$('#myDiv').fadeIn('slow', function() {
   this.style.removeAttribute('filter');
});

As the blog post above explains, this is a rather messy solution.

Excerpt from the blog post, including a cleaner solution to this problem:

This means that every single time we want to fade an element, we need to remove the filter attribute, which makes our code look messy.

A simple, more elegant solution would be to wrap the .fadeIn() and .fadeOut() functions with a custom function via the plugin interface of jQuery. The code would be exactly the same, but instead of directly calling the fade functions, we call the wrapper. Like so:

$('#node').customFadeOut('slow', function() { 
   //no more fiddling with attributes here
});

So, how do you get this working? Just include the following code after you include the jQuery library for the added functionality.

(function($) {
    $.fn.customFadeIn = function(speed, callback) {
        $(this).fadeIn(speed, function() {
            if(jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if(callback != undefined)
                callback();
        });
    };
    $.fn.customFadeOut = function(speed, callback) {
        $(this).fadeOut(speed, function() {
            if(jQuery.browser.msie)
                $(this).get(0).style.removeAttribute('filter');
            if(callback != undefined)
                callback();
        });
    };
})(jQuery);
like image 110
Aron Rotteveel Avatar answered Sep 29 '22 03:09

Aron Rotteveel


One way is to set a background color on the div (normally) white.

like image 39
redsquare Avatar answered Sep 29 '22 01:09

redsquare