Created
February 11, 2014 19:11
-
-
Save joshkehn/8941877 to your computer and use it in GitHub Desktop.
CSS background image preloading without JavaScript. Includes LESS mixin.
This file contains 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
.arrow { | |
background: url("../images/arrow-normal.svg") no-repeat top center; | |
} | |
.arrow:before { | |
background: url("../images/arrow-hover.svg"); | |
display: none; | |
} | |
.arrow:hover { | |
background: url("../images/arrow-hover.svg"); | |
} |
This file contains 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
// Background with hover state and preloading mixin. | |
.background-with-hover ($initial; $hover) { | |
background-image: url($initial); | |
&:before { | |
content: url($hover); | |
display: none; | |
} | |
&:hover { | |
background-image: url($hover); | |
} | |
} | |
// Usage example with the arrow above | |
.arrow { | |
background: no-repeat top center; | |
.background-with-hover("../images/arrow-normal.svg", | |
"../images/arrow-hover.svg"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment