Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
resize sprites in Compass
@mixin resize-sprite($map, $sprite, $percent) {
$spritePath: sprite-path($map);
$spriteWidth: image-width($spritePath);
$spriteHeight: image-height($spritePath);
$width: image-width(sprite-file($map, $sprite));
$height: image-height(sprite-file($map, $sprite));
@include background-size(ceil($spriteWidth * ($percent/100)) ceil($spriteHeight * ($percent/100)));
width: ceil($width*($percent/100));
height: ceil($height*($percent/100));
background-position: 0 floor(nth(sprite-position($map, $sprite), 2) * ($percent/100) );

This comment has been minimized.

Copy link

@escapedcat escapedcat commented Jan 3, 2013

Great mixin! But is it somehow possible to recreate all sprite-map classes again automatically for the second size?
I created a question here:


This comment has been minimized.

Copy link

@wilkerlucio wilkerlucio commented Sep 4, 2013

hey, I did extend your implementation, also added files with usage examples:

my version has a mixin that resizes all the icons at once, which may be helpful :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment