jQuery fadeIn在IE7中留下没有消除锯齿的文本

为什么会这样? 有任何变通方法吗?

jQuery的:

 $(function(){
    $( 'p.quote')淡入(3000)。
 });

HTML:

有人说:

“ lorem ipsum”

别人说:

“ magna carta”

IE和fadeIn / fadeOut函数存在一个已知错误及其对文本元素的影响。 看看这里的信息:

http://blog.bmn.name/2008/03/jquery-fadeinfadeout-ie-cleartype-glitch/

看起来我的原始链接已经死了。 使用评论中的其他解决方案进行了更新:

http://malsup.com/jquery/cycle/cleartype.html

解决方法是在fadeIn()完成后删除回调函数中元素的“filter”属性。

我在http://jquery.malsup.com/fadetest.html上找到了更好,更通用的解决方案。

我已经把它改编成一个独立的JavaScript文件,包含在使用jQuery fade *()方法的页面中。

// // jQuery IE Fade Fix // // Adapted from code found at http://jquery.malsup.com/fadetest.html. // // This is only needed for IE 7 and earlier, so this is best added to your page using IE's conditional comments // (http://msdn.microsoft.com/en-us/library/ms537512%28VS.85%29.aspx) as follows: //  // (function($) { $.fn.fadeIn = function(speed, callback) { if ($.isFunction(speed) && callback == undefined) { callback = speed; speed = 'normal'; } 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) { if ($.isFunction(speed) && callback == undefined) { callback = speed; speed = 'normal'; } 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) { if ($.isFunction(speed) && callback == undefined) { callback = speed; speed = 'normal'; } return this.animate({opacity: to}, speed, function() { if ( to == 1 && $.browser.msie ) { this.style.removeAttribute('filter'); } if ( $.isFunction(callback) ) { callback.call(this); } }); }; })(jQuery); 

编辑:合并了joeformd对回调的修复。

EDIT2:为未定义速度但回调为-Tomi的极端情况添加了修复程序

根据我的记忆,设置的filter属性会导致这种情况。 完成fadeIn后,从元素中删除filter属性。

 $('p.quote').fadeIn(2000, removeFilter); function removeFilter() { $('p.quote').removeAttr("filter"); } 

只需将背景颜色应用于您褪色的精确元素..据我记得,如果您应用于父级,它将不适用于子项,因此它必须位于此元素上才能获得别名。

看起来接受的答案现在有一个死链接。 我认为现在可以在http://blog.wolffmyren.com/2009/05/28/jquery-fadeinfadeout-ie-cleartype-glitch/获得相同的信息。

要保留StackOverflow中的信息,以下是该链接的内容:

感谢Benjamin Michael Novakovic的修复!

jQuery fadeIn / fadeOut IE cleartype故障

在今天使用jQuery javascript库的时候,我注意到了IE7下的一个小故障。 当使用jQuery中的.fadeIn()和.fadeOut()函数淡化html节点时,IE会删除windows Cleartype呈现; 这导致非常难看的文字。 这个问题似乎很常见,但没有人能够解决这个问题。

解决此问题的最常用方法是删除filterCSS属性。 在普通的JavaScript中,它看起来像这样:

 document.getElementById('node').style.removeAttribute('filter'); 

在jQuery中,它看起来像这样:

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

通过Benjamin Michael Novakovic»jQuery fadeIn / fadeOut IE cleartype故障。

  

在html文档之上添加它。 它适用于IE 8.07xxxx。 我不确定这种技术是否适用于IE 7。

将它添加到您的JS中。 它修复了错误并维护了正确的范围。 当添加到jQuery时,它仍然通过所有unit testing:

 (function($){ $.each(['fadeIn', 'fadeOut'], function(i, method){ var _fn = $.fn[method]; $.fn[method] = function(easing, callbackå, cancel) { if ($.isFunction(easing)) { callback = easing; easing = 'normal'; } return _fn.call(this, easing, function(){ jQuery.browser.msie && !cancel && this.style.removeAttribute('filter'); (callback || $.noop).call(this); }); } }) })(jQuery); 

我写的:)

这就是我如何在IE 8上摆脱我丑陋的文字:使用fadeTo代替并将其调整到99%!

因此这对我有用:

 $(function() { $('p.quote').fadeTo("slow",0.99); }) 

这些解决方案都不适合我使用jQuery的动画在div中淡出,因为filter在样式元素中。 因此,我需要做的是:

 $(div).animate({opacity: 1}, 800, function() { $(this).removeAttr('style'); }); 

显然,这将删除您可能拥有的任何其他内联样式。

这些解决方案都不适用于我,否则它们不适合,例如我不想仅针对一个IE错误更改我的HTML5 DTD声明,并且我无法更改我在其他动画中使用的背景颜色。

我也使用jQuery .animate所以这可能有点偏离主题但是完美的解决方案就是这个 。 它是一篇好文章,但核心代码是:

 $('#sample').animate( {opacity:1.0}, 500, function() { $(this).css('filter',''); } );