Skip to content

Instantly share code, notes, and snippets.

@Dkendal
Created October 11, 2013 23:04
Show Gist options
  • Save Dkendal/6943355 to your computer and use it in GitHub Desktop.
Save Dkendal/6943355 to your computer and use it in GitHub Desktop.
Compass rails Sass mixin for resizing sprite
@mixin scale-sprite($map, $sprite, $scale : 1) {
$sprite-file: sprite-file($map, $sprite);
$width-to-map-ratio: sprite-map-width($map)/image-width($sprite-file);
$pos: sprite-position($map, $sprite, 0, 0);
$height: image-height($sprite-file) * $scale;
$width: image-width($sprite-file) * $scale;
$x: nth($pos, 1) * $scale;
$y: nth($pos, 2) * $scale;
display: block;
background-image: $map;
background-position: $x $y;
background-size: percentage($width-to-map-ratio);
height: ceil($height) !important;
width: ceil($width) !important;
}
module Sass::Script::Functions
def sprite_map_width map
binding.pry
Sass::Script::Number.new(map.width,["px"])
end
declare :sprite_map_width, args: [:map]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment