Skip to content

Instantly share code, notes, and snippets.

@gavinblair
Created November 24, 2011 14:49
Show Gist options
  • Save gavinblair/1391501 to your computer and use it in GitHub Desktop.
Save gavinblair/1391501 to your computer and use it in GitHub Desktop.
Preload Images without DOM Manipulation
//preloading images
function preload(source) {
var i = new Image();
i.src = source;
}
preload("img/hover.jpg");
preload("img/active.jpg");
.button {
background-image: url(img/button.png);
}
.button:hover {
background-image: url(img/hover.png);
}
.button:active {
background-image: url(img/active.png);
}
@gavinblair
Copy link
Author

does this work? this guy thinks so http://stackoverflow.com/q/3191946

@gavinblair
Copy link
Author

totally works. just tested it in Firefox.

@gavinblair
Copy link
Author

doesn't work in Chrome, on the mac

@SeanJA
Copy link

SeanJA commented Nov 25, 2011

What does it do in Chrome on the mac?

@gavinblair
Copy link
Author

it just doesn't preload. you still get a flicker when you hover the button.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment