Skip to content

Instantly share code, notes, and snippets.

@SteAllan
Created August 3, 2015 10:01
Show Gist options
  • Save SteAllan/b371b7c6a60b3151b966 to your computer and use it in GitHub Desktop.
Save SteAllan/b371b7c6a60b3151b966 to your computer and use it in GitHub Desktop.
Hi-res Sprite Sheet Mixin, integrating with Sass Breakpoint
@mixin sprite($icon-name, $important: '') {
@if $important != '' {
// @1x resolution screens
background-image: sprite-url($sprite-pri) !important;
background-position: sprite-position($sprite-pri, $icon-name) !important;
// @2x resolution screens
@include breakpoint($hi_res) {
background-image: sprite-url($sprite-pri--2x) !important;
@include background-size(rem(sprite-width($sprite-pri--2x) / 2) rem(sprite-height($sprite-pri--2x) / 2));
background-position: round(nth(sprite-position($sprite-pri--2x, '#{$icon-name}@2x'), 1) / 2) round(nth(sprite-position($sprite-pri--2x, '#{$icon-name}@2x'), 2) / 2) !important;
}
// Print out the icon dimensions
width: rem(image-width('sprite--pri/#{$icon-name}.png')) !important;
height: rem(image-height('sprite--pri/#{$icon-name}.png')) !important;
}
@else {
// @1x resolution screens
background-image: sprite-url($sprite-pri);
background-position: sprite-position($sprite-pri, $icon-name);
// @2x resolution screens
@include breakpoint($hi_res) {
background-image: sprite-url($sprite-pri--2x);
@include background-size(rem(sprite-width($sprite-pri--2x) / 2) rem(sprite-height($sprite-pri--2x) / 2));
background-position: round(nth(sprite-position($sprite-pri--2x, '#{$icon-name}@2x'), 1) / 2) round(nth(sprite-position($sprite-pri--2x, '#{$icon-name}@2x'), 2) / 2);
}
// Print out the icon dimensions
width: rem(image-width('sprite--pri/#{$icon-name}.png'));
height: rem(image-height('sprite--pri/#{$icon-name}.png'));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment