解决IE6下CSS背景图片闪烁的Bug

div,设置了背景图,然后只要在js中对此div的css做出任何更改就会重新请求背景图片,表现为页面闪烁,此问题仅在IE6下出现(更低版本未测试),原因是IE6在默认情况下不缓存背景图片。

解决办法一,通过css:

html {
filter: expression(document.execCommand("BackgroundImageCache", false, true));
}

缺点:可能会使整个页面的加载速度变慢

解决办法二,使用javascript:

<script type='text/javascript'>
document.execCommand(“BackgroundImageCache”, false, true);
</script>

缺点:如果在firefox等浏览器下执行会出错。
所以需要判断是否为IE浏览器,使用jQuery提供的判断方法如下:

<script type='text/javascript'>
if ($.browser.msie) {
document.execCommand(“BackgroundImageCache”, false, true);
}
</script>

原文地址:https://www.cnblogs.com/enone/p/1782864.html