Tôi tìm thấy giải pháp tốt hơn, tổng quát hơn, tại http://jquery.malsup.com/fadetest.html.
Tôi đã thực hiện điều đó và điều chỉnh nó thành một tệp JavaScript độc lập để được bao gồm trong các trang sử dụng các phương thức fade *() của 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);
EDIT: sửa chữa Incorporated joeformd 's cho callbacks.
EDIT2: thêm sửa chữa đối với trường hợp góc nơi tốc độ không được định nghĩa nhưng callback là -Tomi
Vâng, nó không đẹp ở chỗ nó mất dần trong văn bản aliased sau đó ghi lại khoảnh khắc lọc tắt, nhưng nó hoạt động. Chúng ta cũng cần phải làm mờ bộ lọc! Dam IE. – chrisdillon
StackOverflow bị vấn đề này rất nhiều (khi bạn nhấp vào "tải câu trả lời mới"). Tôi hy vọng một trong những đội thấy câu trả lời này. –
Điều này cung cấp một cải tiến nhỏ: http://malsup.com/jquery/cycle/cleartype.html – chrisdillon