IEで奇妙なテキストをレンダリングするJQueryトグル関数(ClearTypeを失いますか?)

StackOverflow https://stackoverflow.com/questions/457929

質問

ボタンがクリックされたときに連絡先フォームを切り替えるこの小さなスクリプトがあります:

$(document).ready(function(){

    $("#button").click(function () {
      $("#form").toggle("slow");
    });

});

Firefoxではすべて正常に動作していますが、IEではトグルのフェードイン効果が100%完了していないようで、完全なレンダリングの前にテキストが「フリーズ」されており、すべての細かい解像度が失われています。

これはトピックを読んでいますが、それを自分に適用する方法が正確にはわかりません問題。

ご協力ありがとうございます。

役に立ちましたか?

解決

これはあなたが探しているものかもしれません。また、別の同様の方法の機能デモがオンラインで利用できます。:

//-------------------------------------------------------------------------------------------------------
// ClearTypeFadeTo / ClearTypeFadeIn / ClearTypeFadeOut
//
// Custom fade in and fade out functions for jQuery that will work around
// IE's bug with bold text in elements that have opacity filters set when
// also using Window's ClearType text rendering.
//
// New Parameter:
// bgColor    The color to set the background if none specified in the CSS (default is '#fff')
//
// Examples:
// $('div').ClearTypeFadeIn({ speed: 1500 });
// $('div').ClearTypeFadeIn({ speed: 1500, bgColor: '#ff6666', callback: myCallback });
// $('div').ClearTypeFadeOut({ speed: 1500, callback: function() { alert('Fade Out complete') } });
//
// Notes on the interaction of ClearType with DXTransforms in IE7
// http://blogs.msdn.com/ie/archive/2006/08/31/730887.aspx
(function($) {
    $.fn.ClearTypeFadeTo = function(options) {
        if (options)
            $(this)
                .show()
                .each(function() {
                    if (jQuery.browser.msie) {
                        // Save the original background color
                        $(this).attr('oBgColor', $(this).css('background-color'));
                        // Set the bgColor so that bold text renders correctly (bug with IE/ClearType/bold text)
                        $(this).css({ 'background-color': (options.bgColor ? options.bgColor : '#fff') })
                    }
                })
                .fadeTo(options.speed, options.opacity, function() {
                    if (jQuery.browser.msie) {
                        // ClearType can only be turned back on if this is a full fade in or
                        // fade out. Partial opacity will still have the problem because the
                        // filter style must remain. So, in the latter case, we will leave the
                        // background color and 'filter' style in place.
                        if (options.opacity == 0 || options.opacity == 1) {
                            // Reset the background color if we saved it previously
                            $(this).css({ 'background-color': $(this).attr('oBgColor') }).removeAttr('oBgColor');
                            // Remove the 'filter' style to restore ClearType functionality.
                            $(this).get(0).style.removeAttribute('filter');
                        }
                    }
                    if (options.callback != undefined) options.callback();
                });
    };

    $.fn.ClearTypeFadeIn = function(options) {
        if (options)
            $(this)
                .css({ opacity: 0 })
                .ClearTypeFadeTo({ speed: options.speed, opacity: 1, callback: options.callback });
    };

    $.fn.ClearTypeFadeOut = function(options) {
        if (options)
            $(this)
                .css({ opacity: 1 })
                .ClearTypeFadeTo({ speed: options.speed, opacity: 0, callback: options.callback });
    };
})(jQuery);

他のヒント

Paulにとって、承認済みの回答ソリューションに追加するトグル関数の作成は簡単です。

$.fn.ClearTypeToggle = function(options) {
    if ($(this).css('opacity') == 1) {
        $(this).ClearTypeFadeOut(options);
    } else {
        $(this).ClearTypeFadeIn(options);
    }
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top