From 569a6065861b66ef258d60172fae3a3693befa42 Mon Sep 17 00:00:00 2001 From: saicaca Date: Wed, 8 Nov 2023 13:01:06 +0800 Subject: [PATCH] feat: overlay scrollbar --- package.json | 1 + pnpm-lock.yaml | 7 ++++ src/components/GlobalStyles.astro | 61 +++++++++++++++++++++++++++++++ src/layouts/Layout.astro | 52 ++++++++++++++++++++------ 4 files changed, 109 insertions(+), 12 deletions(-) diff --git a/package.json b/package.json index 33f473e..924f1b4 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "astro-icon": "1.0.0-next.2", "colorjs.io": "^0.4.5", "mdast-util-to-string": "^4.0.0", + "overlayscrollbars": "^2.4.4", "reading-time": "^1.5.0", "rehype-katex": "^7.0.0", "remark-math": "^6.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 76f8d12..cc3279c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -29,6 +29,9 @@ dependencies: mdast-util-to-string: specifier: ^4.0.0 version: 4.0.0 + overlayscrollbars: + specifier: ^2.4.4 + version: 2.4.4 reading-time: specifier: ^1.5.0 version: 1.5.0 @@ -4285,6 +4288,10 @@ packages: lcid: 1.0.0 dev: false + /overlayscrollbars@2.4.4: + resolution: {integrity: sha512-792lwASLr3FlZER+/P7NseFQjffDEcQOg6HtyBSLrnb3crH+Ybk0tzaljQVQZs0pjGF/xFjyvMKin6whkL0RnQ==} + dev: false + /p-limit@2.3.0: resolution: {integrity: sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==} engines: {node: '>=6'} diff --git a/src/components/GlobalStyles.astro b/src/components/GlobalStyles.astro index b9a3896..170fe9c 100644 --- a/src/components/GlobalStyles.astro +++ b/src/components/GlobalStyles.astro @@ -95,6 +95,18 @@ color_set({ --float-panel-bg: white oklch(0.19 0.015 var(--hue)) + --scrollbar-bg-light: black(0.4) + --scrollbar-bg-hover-light: black(0.5) + --scrollbar-bg-active-light: black(0.6) + + --scrollbar-bg-dark: white(0.4) + --scrollbar-bg-hover-dark: white(0.5) + --scrollbar-bg-active-dark: white(0.6) + + --scrollbar-bg: var(--scrollbar-bg-light) var(--scrollbar-bg-dark) + --scrollbar-bg-hover: var(--scrollbar-bg-hover-light) var(--scrollbar-bg-hover-dark) + --scrollbar-bg-active: var(--scrollbar-bg-active-light) var(--scrollbar-bg-active-dark) + --color-selection-bar: rainbow-light rainbow-dark --display-light-icon: 1 0 @@ -106,6 +118,55 @@ color_set({ ::selection background-color: var(--selection-bg) +.scrollbar-base.os-scrollbar + transition: width 0.15s ease-in-out, height 0.15s ease-in-out, opacity 0.15s, visibility 0.15s, top 0.15s, right 0.15s, bottom 0.15s, left 0.15s; + pointer-events: unset; + &.os-scrollbar-horizontal + padding-top: 4px; + padding-bottom: 4px; + height: 16px; + .os-scrollbar-track .os-scrollbar-handle + height: 4px; + border-radius: 4px; + &:hover + .os-scrollbar-track .os-scrollbar-handle + height: 8px; + &.px-2 + padding-left: 8px; + padding-right: 8px; + &.os-scrollbar-vertical + padding-left: 4px; + padding-right: 4px; + width: 16px; + .os-scrollbar-track .os-scrollbar-handle + width: 4px; + border-radius: 4px; + &:hover + .os-scrollbar-track .os-scrollbar-handle + width: 8px; + &.py-1 + padding-top: 4px; + padding-bottom: 4px; + +.scrollbar-auto + &.os-scrollbar + --os-handle-bg: var(--scrollbar-bg); + --os-handle-bg-hover: var(--scrollbar-bg-hover); + --os-handle-bg-active: var(--scrollbar-bg-active); + +.scrollbar-dark + &.os-scrollbar + --os-handle-bg: var(--scrollbar-bg-dark); + --os-handle-bg-hover: var(--scrollbar-bg-hover-dark); + --os-handle-bg-active: var(--scrollbar-bg-active-dark); + +.scrollbar-light + &.os-scrollbar + --os-handle-bg: var(--scrollbar-bg-light); + --os-handle-bg-hover: var(--scrollbar-bg-hover-light); + --os-handle-bg-active: var(--scrollbar-bg-active-light); + +