tags:

views:

160

answers:

5

I'm using a big Background image on hover which is set in css background {....}

It takes time to load first time upon mouse over so I want to preload this background image.

What is the best option to do this either using pure css or javascript or jquery?

Pls don't suggest me CSS Sprite.

+2  A: 

See:

Preload :hover images in CSS
Preloading Images With CSS

Sarfraz
A: 

If it's for a hover effect, use css sprites and forget javascript. Easier, and fewer http requests.

Mark
in my case i cant use css spite
metal-gear-solid
+2  A: 

You can take a look to the CSS sprites techniques which could decrease considerably your images size. By the way it'll help to preload all hover, or dynamically changing decorations images has they have been loaded at page loading.

Boris Guéry
How come you get 3 upvotes for the same answer, when I answered first? Anyway, apparently this doesn't work for him.
Mark
A: 

Or don't preload it as such.

Have the image contain both states of the image, then use CSS to re-position the image to show the state that you desire.

If you have multiple images, it might be worth implementing a sprite as mentioned by someone else.

Another link: http://www.smashingmagazine.com/2009/04/27/the-mystery-of-css-sprites-techniques-tools-and-tutorials/

Kohan
A: 

If the image is always the same, the following will do it:

pic1= new Image(100,25);
pic1.src="http://someplace.com/image1.gif";

hellsgate
what is this js or css?
metal-gear-solid
@mgs: it is JS.
Mark