Reload backgrounds to fix bug with chrome

*爱你&永不变心* 提交于 2019-12-12 00:59:30

问题


After fixing CSS background-image style formatting to get better compatibility with Firefox and IE, I found that Chrome intermittingly loses the background images when you scroll up and down on the page. It happens not all the time but still so frequent that users will notice that you sometimes loose the background on your side panels and bottom panels.

Being a javascript novice, I started to create something very simple in order to fix the website located at: http://greencoconut.nl/over/

When searching for this problem I found that also others have struggled with this and when trying to fix this. Knowing that I must refresh the image backgrounds I have writen some code.

Here is the javascript for two divs by ID but it will not load with setInterval events:

/** trying to fix bug with backgrounds
 *  source http://blog.andrewcantino.com/blog/2012/02/15/fixing-the-chrome-background-refresh-bug/
 */
jQuery(document).ready(function() {
    divObj = document.getElementById('recent-posts-2');
    strLink = "url('" + "http://greencoconut.nl/wp/wp-content/themes/origami-paper/images/planken-widget-achtergrond.jpg" + "')";
      if (/chrome/.test(navigator.userAgent.toLowerCase())) {
          setInterval(function() {
        divObj.style.backgroundImage = strLink
      }, 3000);
    }
});


jQuery(document).ready(function() {
    divObj = document.getElementById('tag_cloud-2');
    strLink = "url('" + "http://greencoconut.nl/wp/wp-content/themes/origami-paper/images/planken-widget-achtergrond.jpg" + "')";
      if (/chrome/.test(navigator.userAgent.toLowerCase())) {
          setInterval(function() {
        divObj.style.backgroundImage = strLink
      }, 3000);
    }
});

The variables seem to work properly but the interval functions do not start. I also tried it with just one but that does not help either. It is probably something simple but I have trouble finding it. I tried this with and without variables but it does not start the interval function.

来源:https://stackoverflow.com/questions/21588657/reload-backgrounds-to-fix-bug-with-chrome

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!