Skip to content

Instantly share code, notes, and snippets.

@c3ry5
Last active December 19, 2015 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save c3ry5/5900646 to your computer and use it in GitHub Desktop.
Save c3ry5/5900646 to your computer and use it in GitHub Desktop.
Retina sprite generation using sass
@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)
/** 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