@xingwangzhe/stalux 1.21.2 → 1.21.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -15,7 +15,7 @@ const { t } = createTranslator(siteConfig.lang || "zh-CN");
|
|
|
15
15
|
const navs = navsConfig?.items ?? [];
|
|
16
16
|
---
|
|
17
17
|
|
|
18
|
-
<nav aria-label="
|
|
18
|
+
<nav aria-label={t("nav.main")} transition:persist-props>
|
|
19
19
|
<!-- 汉堡菜单按钮 (仅窄屏显示) -->
|
|
20
20
|
<button
|
|
21
21
|
data-ref="stalux-nav-toggle"
|
|
@@ -140,17 +140,17 @@ const navs = navsConfig?.items ?? [];
|
|
|
140
140
|
if (!navList || !btnLeft || !btnRight) return;
|
|
141
141
|
|
|
142
142
|
function updateButtons() {
|
|
143
|
-
const
|
|
144
|
-
const
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
|
|
149
|
-
btnRight.classList.toggle("visible", !atEnd);
|
|
150
|
-
} else {
|
|
151
|
-
btnLeft.classList.remove("visible");
|
|
152
|
-
btnRight.classList.remove("visible");
|
|
143
|
+
const maxScrollLeft = Math.max(0, navList.scrollWidth - navList.clientWidth);
|
|
144
|
+
const hasOverflow = maxScrollLeft > 4;
|
|
145
|
+
const scrollLeft = Math.min(Math.max(navList.scrollLeft, 0), maxScrollLeft);
|
|
146
|
+
|
|
147
|
+
if (navList.scrollLeft !== scrollLeft) {
|
|
148
|
+
navList.scrollLeft = scrollLeft;
|
|
153
149
|
}
|
|
150
|
+
|
|
151
|
+
navList.toggleAttribute("data-overflow", hasOverflow);
|
|
152
|
+
btnLeft.classList.toggle("visible", hasOverflow && scrollLeft > 4);
|
|
153
|
+
btnRight.classList.toggle("visible", hasOverflow && scrollLeft < maxScrollLeft - 4);
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
btnLeft.addEventListener("click", () => {
|
|
@@ -167,6 +167,9 @@ const navs = navsConfig?.items ?? [];
|
|
|
167
167
|
// 用 ResizeObserver 监听容器尺寸变化(窗口缩窄/变宽时重新判断)
|
|
168
168
|
const ro = new ResizeObserver(updateButtons);
|
|
169
169
|
ro.observe(navList);
|
|
170
|
+
if (navList.parentElement) ro.observe(navList.parentElement);
|
|
171
|
+
window.addEventListener("resize", updateButtons, { passive: true });
|
|
172
|
+
window.addEventListener("load", updateButtons, { once: true });
|
|
170
173
|
|
|
171
174
|
// 初始检测
|
|
172
175
|
updateButtons();
|
package/src/i18n/en.json
CHANGED
package/src/i18n/zh-CN.json
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
.navContainer {
|
|
3
3
|
position: relative;
|
|
4
4
|
width: 100%;
|
|
5
|
+
min-width: 0;
|
|
5
6
|
max-width: 100%;
|
|
6
7
|
overflow: hidden;
|
|
8
|
+
box-sizing: border-box;
|
|
7
9
|
}
|
|
8
10
|
|
|
9
11
|
.navList {
|
|
@@ -11,6 +13,9 @@
|
|
|
11
13
|
gap: 2rem;
|
|
12
14
|
align-items: center;
|
|
13
15
|
justify-content: center;
|
|
16
|
+
min-width: 0;
|
|
17
|
+
max-width: 100%;
|
|
18
|
+
box-sizing: border-box;
|
|
14
19
|
transition: transform 0.3s ease;
|
|
15
20
|
/* 当导航项总宽度超过视口时允许横向滚动,防止右侧项被裁剪 */
|
|
16
21
|
overflow-x: auto;
|
|
@@ -21,6 +26,11 @@
|
|
|
21
26
|
-ms-overflow-style: none;
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
.navList[data-overflow] {
|
|
30
|
+
justify-content: flex-start;
|
|
31
|
+
padding-inline: 44px;
|
|
32
|
+
}
|
|
33
|
+
|
|
24
34
|
.navList::-webkit-scrollbar {
|
|
25
35
|
display: none;
|
|
26
36
|
}
|
|
@@ -204,7 +214,7 @@
|
|
|
204
214
|
position: fixed;
|
|
205
215
|
top: 0;
|
|
206
216
|
right: 0;
|
|
207
|
-
width: 220px;
|
|
217
|
+
width: min(220px, calc(100vw - 1rem));
|
|
208
218
|
height: 100vh;
|
|
209
219
|
background: var(--black-20p);
|
|
210
220
|
backdrop-filter: blur(20px);
|