Created
November 24, 2011 14:49
-
-
Save gavinblair/1391501 to your computer and use it in GitHub Desktop.
Preload Images without DOM Manipulation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//preloading images | |
function preload(source) { | |
var i = new Image(); | |
i.src = source; | |
} | |
preload("img/hover.jpg"); | |
preload("img/active.jpg"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.button { | |
background-image: url(img/button.png); | |
} | |
.button:hover { | |
background-image: url(img/hover.png); | |
} | |
.button:active { | |
background-image: url(img/active.png); | |
} |
totally works. just tested it in Firefox.
doesn't work in Chrome, on the mac
What does it do in Chrome on the mac?
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
does this work? this guy thinks so http://stackoverflow.com/q/3191946