Skip to content

Instantly share code, notes, and snippets.

@brandonminch
Created January 29, 2013 19:35
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 brandonminch/4666986 to your computer and use it in GitHub Desktop.
Save brandonminch/4666986 to your computer and use it in GitHub Desktop.
// dynamic sprite
$sprite: sprite-map("sprite/*.png", $spacing: 5);
$sprite-retina: sprite-map("sprite-retina/*.png", $spacing: 30);
$sprite-background: sprite-url($sprite) no-repeat transparent;
$sprite-retina-background-image: sprite-url($sprite-retina);
@mixin background-sprite($selector, $setHeight: false, $setWidth: false, $offset-x: 0, $offset-y: 0, $retina-offset-x: false, $retina-offset-y: false) {
background: $sprite-background;
background-position: sprite-position($sprite, $selector, $offset-x, $offset-y);
background-repeat: no-repeat;
@if $setHeight {
height: image-height(sprite-file($sprite, $selector));
}
text-shadow: none;
@if $setWidth {
width: image-width(sprite-file($sprite, $selector));
}
//retina
@media (-webkit-min-device-pixel-ratio: 2), (-o-min-device-pixel-ratio: 3/2), (min-device-pixel-ratio: 2) {
@if (sprite-position($sprite, $selector) != sprite-position($sprite-retina, $selector)) {
@if ($retina-offset-x) {
$offset-x: $retina-offset-x;
}
@if ($retina-offset-y) {
$offset-y: $retina-offset-y;
}
$ypos: round(nth(sprite-position($sprite-retina, $selector, $offset-x, $offset-y), 2) / 2);
background-position: 0 $ypos;
}
background-size: (ceil(image-width(sprite-path($sprite))), auto);
background-image: $sprite-retina-background-image;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment