@euid/scss-mixins
  • Sass 믹스인 라이브러리
  • Getting Started
    • 시작하기
    • 환경 구성
    • 변경 이력
    • VS Code 확장
  • Utilities
    • 단위 (Unit)
      • rem()
      • em()
      • unitless-px()
      • remove-unit()
      • get-number-or-string()
    • 컬러 (Color)
      • get-color()
      • get-color-name()
      • has-color()
      • alt-color()
      • a11y-color()
      • light-or-dark()
      • color-contrast()
      • most-legible-color()
    • 문자 (String)
      • str-replace()
      • str-split()
      • str-to-num()
      • str-repeat()
      • str-extract-count-keyword()
    • 리스트 (List)
      • first()
      • last()
      • copy-list()
      • merge-list()
      • get-value-after-key()
      • get-match-value-of-keys()
    • 검사 (Validation)
      • is-valid-types()
      • is-valid-keywords()
      • is-include-items()
    • 이징 (Easing)
      • ease()
      • ease-add()
      • ease-merge()
  • Mixins
    • 폰트 (Font)
      • font()
      • font-face()
      • font-size-padding()
    • 텍스트 (Text)
      • text()
      • text-ellipsis()
    • 간격 (Spacing)
      • margin()
      • m()
      • mx()
      • my()
      • padding()
      • p()
      • px()
      • py()
      • space()
      • s()
      • sx()
      • sy()
    • 디스플레이 (Display)
      • show()
      • hide()
      • order()
    • 포지션 (Position)
      • position()
      • relative()
      • absolute()
      • fixed()
      • sticky()
      • static()
    • 플렉스박스 (Flexbox)
      • Flex 컨테이너(Container)
        • flex-container()
        • flex-container-append()
      • Flex 아이템(Item)
        • flex-item()
        • flex()
    • CSS 그리드 (Grid)
      • Grid 컨테이너(Container)
        • grid-container()
        • grid-container-append()
          • grid-rows()
          • grid-cols()
          • grid-auto()
            • auto-rows()
            • auto-cols()
            • auto-flow()
          • grid-areas()
          • gap()
      • Grid 아이템(Item)
        • grid-item()
        • grid-area()
        • grid-row()
          • row-start()
          • row-end()
          • row-span()
        • grid-col()
          • col-start()
          • col-end()
          • col-span()
    • 박스 정렬 (Box Alignment)
      • box-alignment()
      • place()
        • content()
        • items()
        • self()
      • justify-content()
      • align-content()
      • justify-items()
      • align-items()
      • justify-self()
      • align-self()
    • 반응형 웹 (Rsponsive Web)
      • media()
      • rwd-img()
      • rwd-video()
      • rwd-iframe-wrapper()
    • 이니셜라이즈 (Initialize)
      • initialize()
      • normalize()
      • reset-box()
      • reset-box-sizing()
      • reset-img()
      • reset-link()
      • reset-list()
      • reset-dl()
      • reset-abbr()
      • reset-button()
    • 인터페이스 (Interface)
      • appearance()
      • selection()
      • scrollbar()
    • 접근성 (Accessibility)
      • a11y-hidden()
      • focus-visible()
    • 상속 (Inheritance)
      • inherit-box-sizing()
      • inherit-pseudo-elements()
    • 폼 (Form)
      • button()
      • input()
      • radio()
      • search()
      • checkbox()
      • placeholder()
      • textarea()
      • select()
      • select-multiple()
Powered by GitBook
On this page
  • 용도
  • 사용법
  • 로직
  • 참고

Was this helpful?

  1. Mixins
  2. 인터페이스 (Interface)

scrollbar()

스크롤바 (Scroll Bar) 믹스인

Previousselection()Next접근성 (Accessibility)

Last updated 4 years ago

Was this helpful?

용도

스크롤바 모양을 꾸미고자 할 때 사용합니다.

속성은 Blink 및 WebKit 기반 브라우저 (예: Chrome, Edge, Opera, Safari, iOS의 모든 브라우저 등)에서만 사용할 수 있습니다.

사용법

scrollbar() 믹스인을 호출합니다. 썸(Thumb) 크기, 색상, 둥글기, 바(Bar) 색상 등을 설정할 수 있습니다.

scrollbar($size:number, $thumb-color:color, $thumb-radius:number, $bar-color:color)

.scrollbar {
  @include scrollbar(rem(20), #20bebe);
}

매개변수(parameter)

유형(type)

필수(required)

기본 값(default)

$size

number

10px

$thumb-color

color

get-color(black)

$thumb-radius

number

3px

$bar-color

color

위 예시 코드는 아래의 CSS로 컴파일 되어 출력됩니다.

.scrollbar {
  scrollbar-face-color: #20bebe;
  scrollbar-track-color: #0f5656;
}
.scrollbar {
  scrollbar-width: thin;
  scrollbar-color: #20bebe #0f5656;
}
.scrollbar::-webkit-scrollbar {
  width: 1.25rem;
  height: 1.25rem;
}
.scrollbar::-webkit-scrollbar-thumb {
  background: #20bebe;
  border-radius: 3px;
}
.scrollbar::-webkit-scrollbar-track {
  background: #0f5656;
}

로직

scrollbar() 믹스인은 다음의 로직에 의해 작성되었습니다.

@use 'sass:color';

@mixin scrollbar(
  $size: 10px,
  $thumb-color: get-color(black),
  $thumb-radius: 3px,
  $bar-color:
    mix(
      $thumb-color,
      if(
        color.blackness($thumb-color) >= 50%,
        get-color(white),
        get-color(black)
      ),
      45%
    )
) {
  // IE
  & {
    scrollbar-face-color: $thumb-color;
    scrollbar-track-color: $bar-color;
  }

  // Firefox
  & {
    scrollbar-width: thin;
    scrollbar-color: $thumb-color $bar-color;
  }

  // Webkit, Blick
  &::-webkit-scrollbar {
    width: $size;
    height: $size;
  }

  &::-webkit-scrollbar-thumb {
    background: $thumb-color;
    border-radius: $thumb-radius;
  }

  &::-webkit-scrollbar-track {
    background: $bar-color;
  }
}
  1. Sass 컬러(Color) 모듈 사용

  2. 전달 받은 인자 값이 없을 경우, 기본 설정 된 매개변수 값 사용

  3. 전달 받은 인자 값이 있을 경우 썸 크기, 색상, 둥글기, 바 색상 등 값을 설정하여 코드 출력

$bar-color 값을 자동으로 계산하는데 사용되는 로직

Sass의 mix() 함수를 사용해 썸 컬러에 다음 과정을 통해 계산 된 색과 혼합합니다. blackness() 함수를 사용해서 썸 컬러의 값이 검정색에 얼마나 가까운 지 계산(검정색에 가까울 수록 100%에 근접) 합니다.

계산된 값이 50% 보다 크거나 같다면? 썸 색상이 어두운 색이므로 색 구성표에 등록된 하얀색을 사용합니다. 반대로 50% 보다 작다면? 썸 색상이 밝은 색상이므로 색 구성표에 등록된 검정색을 사용합니다.

mix(
  $thumb-color,
  if(
    color.blackness($thumb-color) >= 50%,
    get-color(white),
    get-color(black)
  ),
  45%
)

참고

믹스인에 사용된 Sass의 빌트인 모듈은 다음과 같습니다.

믹스인에 사용된 직접 제작한 모듈은 다음과 같습니다.

썸 색상 명도 대비를 분석해 계산된 색 ( 참고)

::-webkit-scrollbar
@use
@mixin / @include
if()
mix()
color.blackness()
get-color()
로직