我正在经历一些非常奇怪的事情!
我有一个div,我用JS(jQuery)隐藏.
喜欢这个:
$('#myDiv').hide();
然后当我做一个淡出如此:
$("#myDiv").fadeIn('slow');
那么文本会丢失IE中的ClearType,但不会在FF中.如果我用褪色渐变的话,那就没事了.
什么是IE,因为它看起来很可怕,它有什么解决方案.
(我现在有ClearType,你可能会明白)
解决方法
对该主题的快速搜索显示如下:
jQuery fadeIn/fadeOut IE cleartype glitch
问题似乎是CSS“过滤器”属性不会被自动删除.这个问题的最简单的解决办法是手动删除它:
$('#myDiv').fadeIn('slow',function() { this.style.removeAttribute('filter'); });
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);