LoginSignup
5
5

More than 5 years have passed since last update.

compassでspriteする際に個々のファイル名を取得する

Posted at

all-dirname-sprites()みたいに、スプライトの元画像のファイル名を列挙したクラス名を付けたい場合、sprite-names($map)で個々の名前が取れる。

@import "sprite/*.png";
$spr-imgs: sprite-map("sprite/*.png");

// 2倍に拡大して表示する用にbackground-positionを指定するmixin
@mixin low-reso-sprites($name){
    $ypos: round(nth(sprite-position($spr-imgs, $name), 2) *2);
    background-position: 0 $ypos;
} 

// クラス出力
@each $sprite-name in sprite-names($spr-imgs) {
  .#{$sprite-name} {
    @include low-reso-sprites($sprite-name);
  }
}
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5