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

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