Created
October 11, 2013 23:04
-
-
Save Dkendal/6943355 to your computer and use it in GitHub Desktop.
Compass rails Sass mixin for resizing sprite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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