Skip to content

Instantly share code, notes, and snippets.

@johnny5th
Created June 18, 2014 21:40
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 johnny5th/8369ffcbec8ef6a1ab4e to your computer and use it in GitHub Desktop.
Save johnny5th/8369ffcbec8ef6a1ab4e to your computer and use it in GitHub Desktop.
Compass Sprite Generator Mixin
$sprites: sprite-map("sprites/*.png", $spacing: 15px);
$sprites2x: sprite-map("sprites2x/*.png", $spacing: 30px);
@mixin sprite-background($name) {
background-image: sprite-url($sprites);
background-position: sprite-position($sprites, $name);
background-repeat: no-repeat;
display: block;
height: image-height(sprite-file($sprites, $name));
width: image-width(sprite-file($sprites, $name));
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
// Workaround for https://gist.github.com/2140082
@if (sprite-position($sprites, $name) != sprite-position($sprites2x, $name)) {
$ypos: round(nth(sprite-position($sprites2x, $name), 2) / 2);
background-position: 0 $ypos;
}
// Hard coded width of the normal sprite image. There must be a smarter way to do this.
@include background-size($normal-sprite-width auto);
background-image: sprite-url($sprites2x);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment