Я провел последние 4 часа, пытаясь найти способ создания спрайта с помощью Compass и sass, который также автоматически масштабирует каждое отдельное изображение для использования с свойством background-size.Compass Sprite Image and Scale
Ничего не найдено, не могу поверить, что это так сложно.
Есть ли у кого-нибудь рабочий пример?
Edit: Это то, что я до сих пор
@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));
}
@mixin resize-sprite-set($map, $percent, $only...) {
$name: sprite_map_name($map);
@each $sprite in sprite_names($map) {
@if length($only) == 0 or index($only, $sprite) != false {
.#{$name}-#{$sprite} {
@include resize-sprite($map, $sprite, $percent);
}
}
}
}
The подмешать возвращается без ошибок.
$my-icons-spacing: 10px; // give some space to avoid little pixel size issues on resize
@import "my-icons/*.png";
$my-icons-sprite-dimensions: true;
@include all-my-icons-sprites;
// the fun part
.small-icons { // overriding all sprites
@include resize-sprite-set($my-icons-sprites, 40); // 40% sized
}
.some-part-of-my-site {
@include resize-sprite-set($my-icons-sprites, 40, logo, ok); // will create overrides only for sprites "logo" and "ok"
}
Я получаю следующее сообщение об ошибке из вышеприведенной реализации при попытке скомпилировать. Приложение Via Prepros.
remove ../images/my-icons-s9e77ab1ef1.png
create ../images/my-icons-s9e77ab1ef1.png
error style.scss (Line 62 of _mixins.scss: Undefined mixin 'resize-sprite-set'.)
identical ../css/style.css
Незнайка, если это помогает, но [это кажется связанным] (HTTP: // StackOverflow. ком/вопросы/12745682/компас-спрайт-изображение-масштабирование). Может быть, вы могли бы показать нам, что не работает? –
Я добавил код, который я использую. – Chozen