如何防止 requestAnimationFrame() 在 IE11 中闪烁?

How to prevent requestAnimationFrame() flickering in IE11?

我正在尝试为 IE 11 中的 requestAnimationFrame() 方法找到修复方法。我一直在浏览网页以寻找解决方案。到目前为止,我已经尝试包含 polyfills,但错误并没有消失。

有人有解决 IE11 错误的方法吗?

这是一个使用 jQuery 3.4 的 example,它对 fadeToggle() 方法使用 requestAnimationFrame() 方法。您将能够在 IE11.

中检查闪烁

您可以尝试使用下面提到的一种合适的方法来解决问题。

  1. 添加背景色 在淡入或淡出的元素上使用 CSS 设置背景颜色。这是解决问题的最基本方法。

  2. 删除 CLEARTYPE 过滤器 在元素淡入淡出后,您可以添加这个简单的回调函数来修复错误。

$('#fadingElement').fadeIn(2000, function(){
       this.style.removeAttribute('filter');
});

  1. 使用自定义 FADEIN/OUT 方法 此方法可替代 jQuery.
  2. 的内置 fadeIn() 和 fadeOut() 方法

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

参考文献:

(1) jQuery fadeIn & fadeOut Problems in Internet Explorer

(2) How to Fix jQuery's Fade In/Out Functions for Internet Explorer

注意:我在代码片段中添加了代码,因为该站点未使用代码块正确格式化代码。