2

I already know how to preload an image with Image.onload. But what about preloading a style.background image?

I need this for a game that's going to be preloading sprite sheets for different levels of a DHTML game.

I've had no success figuring out how to get style.background to use an Image object.

So how do I preload a style.background image, only with Javascript.

2
  • is there a reason why you can't preload it in the HTML itself and have it hidden in the CSS? Commented Nov 1, 2010 at 9:50
  • the key phrase in my question is "different levels" - I don't want the player to have to download all assets at once Commented Feb 8, 2011 at 17:41

1 Answer 1

1

Just preload it the normal way.

The image will be cached in any case, regardless whether you use it as an img element, or as a background-image property.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.