Last active
December 19, 2015 04:58
-
-
Save c3ry5/5900646 to your computer and use it in GitHub Desktop.
Retina sprite generation using sass
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
@mixin sprite-background($name) | |
background-repeat: no-repeat | |
background-image: $standardImg | |
background-position: sprite-position($sprites, $name) | |
height: image-height(sprite-file($sprites, $name)) | |
width: image-width(sprite-file($sprites, $name)) | |
@media (-webkit-min-device-pixel-ratio: 1.5), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 1.5) | |
background-image: $retinaImg | |
background-position: 0 round(nth(sprite-position($sprites2x, $name), 2) / 2) | |
height: round(image-height(sprite-file($sprites2x, $name)) / 2) | |
width: round(image-width(sprite-file($sprites2x, $name)) /2 ) | |
/** width of largest image in non retina folder **/ | |
+background-size(290px auto) |
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
/** image directory **/ | |
$imgdir : "/static/1/images" | |
/** wildcarded import function for retina and non retina **/ | |
@import "non_retina/*.png" | |
@import "retina/*.png" | |
/** create sprite in sass memmory **/ | |
$sprites: sprite-map("non_retina/*.png") | |
$sprites2x: sprite-map("retina/*.png") | |
/** url of generated sprites **/ | |
$standardImg: url(#{$imgdir}/non_retina-sfe26373e53.png) | |
$retinaImg: url(#{$imgdir}/retina-s9b09948543.png) | |
/** compass sheets required **/ | |
@import compass/utilities | |
@import mixins | |
.img | |
+sprite-background(image_name_without_extension) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment