2009-04-22 75 views
20

爲什麼會發生這種情況?任何解決方法?jQuery fadeIn在IE7中使文本不會反鋸齒

的jQuery:

 
$(function() { 
    $('p.quote').fadeIn(3000); 
}); 

HTML:

 
<p>someone said:</p> 
<p class="quote">&ldquo;lorem ipsum&rdquo;</p> 
<p>someone else said:</p> 
<p class="quote" style="display: none;">&ldquo;magna carta&rdquo;</p> 

回答

20

沒有與IE和淡入/淡出功能以及它們對文本元素效果的已知錯誤。這裏退房信息:

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

看起來像我原來的鏈接從那以後死了。與來自評論的不同的解決方案更新:

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

解決方法是淡入之後去除在回調函數的元素的「過濾器」屬性()已經完成。

+1

那麼,它在它的別名文字淡化然後迅速過濾掉,但它的工作原理是不漂亮。我們也需要淡化過濾器!水壩IE。 – chrisdillon 2009-04-22 17:14:56

+1

StackOverflow的就在這個問題的困擾(當您單擊「加載新的答案」)。我希望其中一個團隊看到這個答案。 – 2009-04-22 17:20:41

5

從我記得,被設置的過濾器屬性導致這一點。在你的fadeIn完成後,從元素中刪除filter屬性。

$('p.quote').fadeIn(2000, removeFilter); 

function removeFilter() { 
    $('p.quote').removeAttr("filter"); 
} 
2

看起來接受的答案現在有一個死鏈接。我想現在可以在http://blog.wolffmyren.com/2009/05/28/jquery-fadeinfadeout-ie-cleartype-glitch/找到相同的信息。

要保留在StackOverflow上的信息,這裏有鏈接的內容:

感謝本傑明·邁克爾·諾瓦科維奇 此修復!

jQuery的淡入/淡出IE的ClearType故障

在使用jQuery JavaScript庫今天在工作中,我發現IE7下 毛刺。當使用jQuery中的.fadeIn()和.fadeOut() 函數淡化html 節點時,IE將刪除窗口Cleartype呈現的 ;其中 導致非常難看的文字。這 問題似乎很常見,但 沒有人有 問題的很好的解決方案。

解決此問題的最常見方法是刪除過濾器CSS 屬性。在普通的JavaScript,它 應該是這樣的:

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

和jQuery的,它應該是這樣的:

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

通過本傑明·邁克爾·諾瓦科維奇» jQuery的淡入/淡出IE的ClearType 毛刺。

17

我在http://jquery.malsup.com/fadetest.html找到了一個更好,更一般的解決方案。

我已經採取和調整成JavaScript文件被包含在使用jQuery的淡入淡出*()方法的頁面獨立。

// 
// 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: 
//  <!--[if lt IE 8]><script type="text/javascript" src="jquery-ie-fade-fix.js"></script><![endif]--> 
// 
(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

3

簡單適用的背景顏色,你褪色確切元素..據我記得它不會對孩子的工作如果,如果你適用於父母,所以它必須是這一點,得到別名非常元素。

1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

將此添加到您的html文檔的頂部。它適用於IE 8.07xxxx。我不知道這種技術適用於IE 7

1

這種添加到您的JS。它修復了錯誤並保持了正確的範圍。當添加到jQuery的,它仍然通過了所有的單元測試:

(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); 

我寫的:)

0

這些解決方案的工作使用jQuery的動畫在一個div我衰落,因爲過濾器是在風格元件。因此,我需要做的是:

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

很明顯,這將刪除您可能也有的任何其他內聯樣式。

0

這些解決方案的工作對我來說無論要不然他們是不合適的,例如我不想改變我的HTML5 DTD聲明只是一個IE錯誤,我不能改變我的背景顏色爲正在使用在另一個動畫。

我也使用jQuery .animate所以這可能有點偏離主題,但完美工作的解決方案是this one。它是一種很好的文章,但核心代碼:

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

這是我擺脫了我的醜文字褪色的IE 8的:使用fadeTo,而不是和齒輪它高達99%!

因此這個工作對我來說:

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