0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Sass 3.3で画像ファイル名に@2xを付ける関数

Posted at

Retinaディスプレイ用の画像のために変数を定義するのがダルいので関数で@2xを付けれるようにしました。

function-image-retina.scss
@function image-retina($image, $suffix: '@2x') {
  $pos: str-index($image, '.');
  $proc: $pos;

  @while ($proc > 0) {
    $i: str-index(str-slice($image, $proc + 1), '.');
    @if $i > 0 {
      $pos: $i;
    }
    $proc: $i;
  }

  $pos: if($pos > 0, $pos, str-length($image) + 1);
  $file-name: str-insert($image, $suffix, $pos);
  @return image-url("#{$file-name}");
}
$image-logo: "logo.png";

#site-name a {
  background-image: image-retina($image-logo);  // => url("images/logo@2x.png")
}
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?