尾风- 滚动栏
用于自定义浏览器滚动条的 Tailwindcs 插件 .
安装
# Using npm
npm install -D @gradin/tailwindcss-scrollbar
# Using Yarn
yarn add -D @gradin/tailwindcss-scrollbar
然后将插件添加到 tailwind.config.js 文档.
module.exports = {
theme: {
// ...
},
plugins: [
require('@gradin/tailwindcss-scrollbar'),
],
}
配置
您可以自定义滚动条的大小和颜色 。 还支持任何 Css 属性,例如 borderRadius。 。 。 .
见 发布注释 如果您正在从 v1 qq 升级
module.exports = {
theme: {
// ...
},
plugins: [
require('@gradin/tailwindcss-scrollbar')({
size: '5px', // width or height, default '5px'
track: {
background: 'lightgray', // default '#f1f1f1'
// add other css attributes here,
// will be merged to ::-webkit-scrollbar-track
},
thumb: {
background: 'gray', // default '#c1c1c1'
borderRadius: '40px',
// add other css attributes here,
// will be merged to ::-webkit-scrollbar-thumb
},
hover: {
background: 'darkgray', // default '#a8a8a8'
borderRadius: '40px',
// add other css attributes here,
// will be merged to ::-webkit-scrollbar-thumb:hover
},
}),
],
}
要使用您配置中的属性 。 主题,您需要覆盖 theme.scrollbar.DEFAULT。 。 。 .
module.exports = {
theme: {
// ...
scrollbar: theme => ({
DEFAULT: {
size: theme('spacing.1'),
track: {
background: theme('colors.gray.300'),
},
thumb: {
background: theme('colors.gray.400'),
},
hover: {
background: theme('colors.gray.500'),
},
},
})
},
plugins: [
require('@gradin/tailwindcss-scrollbar'),
],
}
多个滚动条样式
您可以使用 theme.scrollbar.STYLE_NAME
他们需要 size, (中文(简体) ), track, (中文(简体) ), thumb, (中文(简体) ), hover 指定属性,因为它们没有默认值.
module.exports = {
theme: {
// ...
scrollbar: {
thin: {
size: '2px',
track: { background: 'lightgray' },
thumb: { background: 'gray' },
hover: { background: 'darkgray' },
},
blue: {
size: '8px',
track: { background: 'lightblue' },
thumb: { background: 'blue' },
hover: { background: 'darkblue' },
},
},
},
}
<div class="overflow-auto scrollbar-thin"></div>
<div class="overflow-auto scrollbar-blue"></div>
黑暗模式
要在暗模式下设置不同的背景颜色, 您可以使用 darkBackground 属性。 如果未设定, 它们的颜色与 background。 。 。 .
track: {
background: theme('colors.gray.300'),
darkBackground: theme('colors.gray.800'),
},
thumb: {
background: theme('colors.gray.400'),
darkBackground: theme('colors.gray.600'),
},
hover: {
background: theme('colors.gray.500'),
darkBackground: theme('colors.gray.500'),
},
隐藏滚动条.
隐藏滚动条,但仍使其可以滚动,使用 scrollbar-none 类
元素的 overflow: auto | scroll。 。 。 .
<div class="overflow-auto scrollbar-none">
<!-- Very long content here -->
</div>
这是通过使用 scrollbar-width: none 灭火器和 ::-webkit-scrollbar{display:none} 在克罗姆岛.
浏览器支持
此插件使用 ::-webkit-scrollbar 以修改滚动条样式.
不支持在 firefox 的所有版本 财务报告和审定财务报表 边缘版本 78 或以上。 。 。 .
.scrollbar-none 支持在 Firefox 64 版本或更新版本。 。 。 .