1
1

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.

透過色を、同じ色に見える非透過色に変換するStylusの関数

Last updated at Posted at 2019-09-14

言葉で説明するのが難しいけど、rgba(255,0,0,0.5)#ff7f7fに変換する関数を作りました。

Stylusのビルトイン関数 transparentifyの逆バージョンみたいなやつ。

背景色を指定すると、その背景色に重ね合わせたときに実際に目に見える色に変換されます。


// color: 変換したい透過色
// background: 透過色の背景
untransparentify(color, background = #fff)
  if alpha(color) == 1
    return color

  else
    if alpha(background) < 1
      background = untransparentify(background)

    base = alpha(color, 1)
    percentage = alpha(color) * 100%

    return mix(base, background, percentage)
1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?