Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8888119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:58:02+00:00 2026-06-14T21:58:02+00:00

It seems I’m not changing background properly when I’m switching between two div or

  • 0

It seems I’m not changing background properly when I’m switching between two div or anchor backgrounds, either directly in JS or using jQuery, with Chrome.

The crossbrowser test is as follow:

Opera 12 – OK
FF 15.01 – OK
IE8 – OK!
Safari 5.1.7 – OK
Chrome 22.0.1229.94 – Not working

Whenever I switch a background in a script or directly using a console, there’s always a 200-500ms pause with no background at all, so my website looks ugly. My top menu mousehover/mouseleave effects are ugly, my trees effects with expand/collapse looks ugly, etc.

The two methods I’m using are:

[JS]     => element.style.backgroundImage = "url(siteimgs/image.png)";
[jQuery] => $('#element').css({ 'background': 'url(siteimgs/image.png)' });

I’ve read about it for IE8:

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

Should I change some server-side settings so that images are received with more refresh informations in the http response?

[EDIT]

Strange, I fiddled it and it works like a charm:
http://jsfiddle.net/2wVND/6/

[EDIT 2]

I tested a lot of plugins and noticed that no preloading method works in Chrome.

[EDIT 3]

I’ve finally read in another thread that I need this in my response header to avoid this Chrome bug:
Cache-control: public; max-age=31536000

But I -really- don’t want to modify this behavior in the server everytime I debug my website.

[EDIT 4]

Ok. Temporary solution that doesn’t require any preloading method nor header modification: switching the visibility between two state images placed one next to the other. Very clean, and still perfect for old browsers.

Example:

<div id="element172635">
    <div id="collapsed172635" style="background: url(collapsed.png); display: inline-block;"></div>
    <div id="expanded172635" style="background: url(expanded.png); display: none;"></div>
</div>

<script>
function toggle(state)
{
    var c = '';
    var e = '';
    if (state == 'expand')
    {
        e = '';
        c = 'none';
    } else
    {
        e = 'none';
        c = '';
    }

    collapsed172635.style.display = c;
    expanded172635.style.display = e;            
}
</script>

That’s dirty but crossbrowser compatible and not longer to implemented than switching the image on an element. I’m using it in a tree with 100s of elements/subelements and there’s no flickering in any browser.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T21:58:03+00:00Added an answer on June 14, 2026 at 9:58 pm

    I’ll publish my workaround as an answer.

    Here is a dirty method to prevent background flickering in Chrome without any plugin or server side setting when switching between two states.

    <div id="element172635">
        <div id="collapsed172635" style="background: url(collapsed.png); display: inline-            block;">
        </div>
        <div id="expanded172635" style="background: url(expanded.png); display: none;">
        </div>
    </div>
    
    <script>
    function toggle(state)
    {
        var c = '';
        var e = '';
        if (state == 'expand')
        {
            e = '';
            c = 'none';
        } else
        {
            e = 'none';
            c = '';
        }
    
        collapsed172635.style.display = c;
        expanded172635.style.display = e;            
    }
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seems like $(img).next().hide(); is not working when both the image and div tag are
Seems to be a fairly hit issue, but I've not yet been able to
Seems like tooltips that you get from attribute title=test are not displayed inside the
Seems the Google-recommended way (using the android support library) for a fragment or activity
Seems elementary but I am not sure how to get each bit from a
Seems impossible to sleep a thread using boost::thread. Method sleep requires a system_time but
Seems like this would be a common question, though I could not find it
Seems begineer but i really do not understand what these lines of code saying,
Seems like there are two products with similar names, but isn't what I expect.
Seems it is a question about .htaccess , not sure what should I use.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.