- This topic is empty.
April 11, 2011 at 8:21 pm #32322
Hi! I am using a full-screen photo as a background. My goal was to set a low res version initially then load a high res version after the page had finished loading. The best way I found to accomplish this was using jQuery but when I set the css attribute the initial low res image was removed (white bg) until the high res version loaded. I spent a long time trying to figure out how to resolve this and it is now working so I thought I’d post what I found and see if anyone has any better method.
color/transparent didn't matter
background-position: center center;
this is what I had initially, so the fix is the next line:
April 12, 2011 at 11:43 am #51507Chris CoyierKeymaster
You might have to do something fancy like inject the high res onto the page as an img, just hidden with CSS. Then watch for that img’s load event, and then replace the background image, that way it’ll snag the image from cache and go faster.April 13, 2011 at 3:39 am #51517
Thanks for the follow-up, Chris. Do you think that’s easier than this solution? Seems that putting both the initial low res and high res backgrounds on the addClass solves this pretty simply. With your response and none from anyone else I must be on to something.April 13, 2011 at 3:42 am #51518
Or do you have a better method of progressively loading the sites background image after the content has loaded?July 30, 2011 at 3:14 pm #84275jtrinkerParticipant
I’m trying to replace a low-resolution full screen background image with a high-resolution image after the high res image finishes loading. I found your code snippet but it doesn’t seemto be working for me.
****BACKGROUND IMAGE TRANSITION TEST****
*This is a test*
And then the jquery:
When I test it only the low-res image loads. It seems like the jquery is loading the .bgHighRes css class but not the image. Any ideas?
Thank you!July 30, 2011 at 3:27 pm #84276Historical Forums UserParticipant
@jtrinker you must put the 2 .js scripts one after the other and before the style tag: first include jquery library and after that , include the other script !
Also, take a close look at Chris’s post!
Cheers!July 30, 2011 at 4:12 pm #84277jtrinkerParticipant
Thank you! That fixed it. I appreciate you looking at it.
- The forum ‘CSS’ is closed to new topics and replies.