views:

441

answers:

2

I am creating a page that uses AJAX to switch content, and each of the 5 pages have their own background colour.

Changing the page, makes the current background animate to the new one. I have 24bit PNGs with alpha transparency which overlay the background colours changing (it works alright).

There is however, one small problem. On occasion, in Firefox 3.5.1 at least, and Safari 3/4, the background will change, however my #main-container div will not. The container has background: transparent to be sure.

The problem is, this doesn't occur everytime, only sometimes. Could this just be a quirk of what I'm making the browser do?

I am using a jQuery plugin to animate the background colour.

I was wondering, does anyone know how I could force the #main-container to inherit it's parent container's (body) background?

I know I could ping it with a setInterval(), but that will be an ugly solution.

Any suggestions very appreciated.

The site is viewable @ http://www.acura.com.au/~kohana/

There is a menu to the right, and clicking those sections are where the problem is. You may have to navigate at least 8 times or so to see the quirk.

Any help is very much appreciated!

UPDATE

I'm going to attempt a setInterval() to check the colours... but not sure what exactly I'll do if I detect them being wrong.

+1  A: 

To follow on from my above comment with respect to timing (sorry this isn't an actual answer, but there's not enough room in the comment field)... I think the problem is due to the timing of the following two events:

  1. The dynamic (async) load of the new stylesheet
  2. The updatePage function where you grab the background colour to fade to

The problem (if i'm reading your code right) is that you're grabbing the colour to fade to from a div which is styled by the style sheet that you're dynamically loading. If it hasn't finished loading (not just the downloading, but the application of styles to the DOM), then the background colour you grab will be the old one.

So steps to take from here... firstly try changing the timeout on your CSS loader to be really small & see if that makes the bug appear more often (or make it larger & see if it goes away). If this seems to match up, then a possible solution is to use a timeout in a loop that testing the background colour against the known old colour until you see it change & then carry on with your background animation, etc.

Hope that helps...

Alconja
Unfortunately, I don't think that's the solution because the first version had all the stylesheet info in one big CSS file (no dyanmic loading of it) and the problem was there. I also used a crude alert on the `backgroundFadeTo` var and it was always the right backgroundColor. Were you able to reproduce my problem? Thanks for your answer.
alex
I believe I reproduced it once. It looked like the `div.main-container` changed colour properly, but the `body` hadn't... Could it have anything to do with the fact that you're doing: `$('#main-container').css('background', backgroundFadeTo);` explicitly in the `updatePage` function (in the animate's callback) but don't do the same to `$("body")`?
Alconja
I think that was just something I had tried to fix the problem. It seems to happen a lot more in Safari. Thanks for looking into it for me.
alex
Ah yes, I've seen it now (was using Fx3.5, but just tried it in Safari). Visually it looks like the `#main-container`'s background colour switches to white immediately before fading to its new colour (rather than fading from its old colour), right? ...if that's the case, is there any need for the setting/animating of the background colour on main container at all? Can't you just do it purely on the body's background? (or is the reason you added the colour to the main container an attempt to get around the issue in the first place?)
Alconja
I think the reason I did it is to get around the issue that was happening. But I'm glad you've finally seen the odd quirk! It looks like Safari is the culprit, and I can't think of anything to *kick it into gear** for this to work.
alex
I've voted you up - whilst you haven't given me an exact answer, an upvote certainly helps with you winning some of the bounty :)
alex
:) Cheers. I just hope you can get it fixed... I know how weird/annoying/hard-to-reproduce browser specific bugs like this can be.
Alconja
A: 

I have a question about the technical part of the site, As I see (am I mistaking?), you get the css via ajax, when a menu is clicked. Images also. I think here it would be a better idea if you get everything from the server when the page loads, then switch css classes on your tags. This would probably solve your random issue, too. Ex: for the background animation you only need to switch two classes, with animation.

Eduárd
Thanks for your answer - however I had done that originally and the problem remained. It's kind of hard to explain. I'll try and post a screenshot.
alex