Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Scrollbar for UnoCSS preset.

License

NotificationsYou must be signed in to change notification settings

unocss-community/unocss-preset-scrollbar

Repository files navigation

NPM versionnpm

aunocss preset for scrollbar,here is ademo

English |简体中文

Installation

npm i unocss-preset-scrollbar unocss -D

Usage

// unocss.config.tsimport{defineConfig,presetAttributify,presetUno}from'unocss'import{presetScrollbar}from'unocss-preset-scrollbar'exportdefaultdefineConfig({presets:[presetUno(),presetAttributify(),presetScrollbar({// config}),],})
<divclass="scrollbar scrollbar-rounded scrollbar-w-4px scrollbar-radius-2 scrollbar-track-radius-4 scrollbar-thumb-radius-4"/>

it will generate below css:

/* layer: shortcuts */.scrollbar::-webkit-scrollbar{width:var(--scrollbar-width);height:var(--scrollbar-height);}.scrollbar{overflow:auto;scrollbar-color:var(--scrollbar-thumb)var(--scrollbar-track);--scrollbar-track:#f5f5f5;--scrollbar-thumb:#ddd;--scrollbar-width:8px;--scrollbar-height:8px;--scrollbar-track-radius:4px;--scrollbar-thumb-radius:4px;}.scrollbar-rounded::-webkit-scrollbar-thumb{border-radius:var(--scrollbar-thumb-radius);}.scrollbar-rounded::-webkit-scrollbar-track{border-radius:var(--scrollbar-track-radius);}.scrollbar::-webkit-scrollbar-thumb{background-color:var(--scrollbar-thumb);}.scrollbar::-webkit-scrollbar-track{background-color:var(--scrollbar-track);}/* layer: default */.scrollbar-radius-2{--scrollbar-track-radius:0.5rem;--scrollbar-thumb-radius:0.5rem;}.scrollbar-thumb-radius-4{--scrollbar-thumb-radius:1rem;}.scrollbar-track-radius-4{--scrollbar-track-radius:1rem;}.scrollbar-w-4px{--scrollbar-width:4px;}

you can also useAttributify Mode

<divscrollbar="~ rounded"/>

or use@apply

import { defineConfig, presetAttributify, presetUno, transformerDirectives } from 'unocss'import { presetScrollbar } from 'unocss-preset-scrollbar'export default defineConfig({  presets: [    presetUno(),    presetAttributify(),    presetScrollbar({    }),  ],+  transformers: [+    transformerDirectives(),+  ],})
.my-custom-scrollbar {@apply scrollbar scrollbar-rounded}

Configurations

FieldDefaultDescription
scrollbarWidth8pxdefault scrollbar width
scrollbarHeight8pxdefault scrollbar height
scrollbarTrackRadius4pxdefault scrollbar track radius
scrollbarThumbRadius4pxdefault scrollbar thumb radius
scrollbarTrackColor#f5f5f5default scrollbar track background color
scrollbarThumbColor#ddddefault scrollbar thumb background color
numberToUnitvalue => `${value / 4}rem`number to unit
varPrefix''the css variable prefix of this preset
prefix''Apply prefix to all utilities and shortcuts
noCompatible'true'iffalse, it usescrollbar-width andscrollbar-color,work in Firefox, butscrollbar-h,scrollbar-w andscrollbar-radius will not work

for example

<divclass="scrollbar scrollbar-w-4">

if we use default options,scrollbar-w-4 will generate--scrollbar-width: 1rem

if we set customnumberToUnit

exportdefaultdefineConfig({presets:[presetUno(),presetScrollbar({numberToUnit:value=>`${value}px`,}),],})

will generate--scrollbar-width: 4px

Utilities

scrollbar

scrollbar-thin

.scrollbar-thin {scrollbar-width: thin; // if noCompatible is true, remove this line--un-scrollbar-width:8px;--un-scrollbar-height:8px;}

scrollbar-none

.scrollbar-none {scrollbar-width: none;}.scrollbar-none::-webkit-scrollbar {display:none;}

rounded

scrollbar-rounded

Make thumb and track have rounded corners

color

scrollbar-(track|thumb)-color-<color>

set track or thumb background color

size

scrollbar-(radius|w|h|track-radius|thumb-radius)-(\d+?)([a-zA-Z]*?)

typedescription
radiusset thumb radius and track radius
wset scrollbar width
hset scrollbar height
track-radiusset track radius
thumb-radiusset thumb radius

**Attention,**if it ends with number,the preset will use numberToUnit to generate length with number as params,Otherwise it will use the captured length information directly

for example:

  • scrollbar-w-4 will be--scrollbar-width: 1rem
  • scrollbar-w-4px will be--scrollbar-width: 4px
  • scrollbar-w-4rem will be--scrollbar-width: 4rem

::: warningif setnoCompatible valuefalse,it not work:::

other

basestarter-ts

License

MIT License © 2021kkopite

About

Scrollbar for UnoCSS preset.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Contributors3

  •  
  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp