I have a link that starts with one background image and then changes on hover to another. Both background images are set in the CSS. My browsers (any of them) don't seem to load the hover image until you actually hover. But then you end up with a blank image for the several seconds (on my very slow connection) it takes to load the new one. Is there a way to encourage the browser to pre-load the hover image so that delay time doesn't occur on hover?
Tell me more
×
Webmasters Stack Exchange is a question and answer site for
pro webmasters. It's 100% free, no registration required.
|
1) Use CSS Sprites (This is the preferred method). 2) Load the images in a hidden div. Place the images in the div and then set the div's CSS to
4) Use this JavaScript
|
|||||
|
|
add this above your css var images = ['img1.jpg', 'img2.jpg']; for(var i = 0, len = images.length; iIf you got the sprite route as danp suggests you still have an issue with loading the sprite before its needed. That said I love sprites, to easily make them I use the tool from Souders |
|||
|
|
|
I don't really like the javascript solution - it's messy, difficult to maintain, and of course completely fails when JS is disabled. The modern solution is to use CSS Sprites - try it, believe me, you'll wonder why you never did this before ;) |
|||
|
|