jQuery 토글 함수 IE에서 이상한 텍스트를 렌더링합니다 (ClearType를 잃어버린다?)
-
19-08-2019 - |
문제
버튼을 클릭하면 연락처 양식을 전환하는이 작은 스크립트가 있습니다.
$(document).ready(function(){
$("#button").click(function () {
$("#form").toggle("slow");
});
});
모든 것이 Firefox에서 OK 작동하지만, 즉, 토글의 페이드 인 효과가 100% 완료되지 않는 것처럼 보이며, 텍스트가 완전한 렌더링 전에 어딘가에 '얼어 붙은'것 같습니다.
나는 이것을 읽었다 주제 그러나 나는 그것을 내 문제에 적용하는 방법을 정확히 모른다.
도움을 주셔서 감사합니다.
해결책
이것이 당신이 찾고있는 것일 수 있습니다. 또한, a 다른 유사한 방법의 기능적 데모 사용 가능한 온라인.:
//-------------------------------------------------------------------------------------------------------
// 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);
}
}
제휴하지 않습니다 StackOverflow