Skip to content

Commit 7415155

Browse files
committed
docs: fix back to top does not work and the document tab title does not sticky after the layout is modified
1 parent f0fb1f3 commit 7415155

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

examples/sites/src/views/components/components.vue

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</div>
1717
<span class="docs-header-spacer"></span>
1818
</header>
19-
<div class="docs-content" id="doc-layout-scoller">
19+
<div class="docs-content" id="doc-layout-scroller">
2020
<div class="ti-rel cmp-container">
2121
<div class="flex-horizontal docs-content-main">
2222
<div class="docs-tabs-wrap">
@@ -233,11 +233,12 @@
233233
<div class="cmp-page-anchor catalog" v-if="currAnchorLinks.length">
234234
<tiny-anchor
235235
id="anchor"
236+
:offset-top="56"
236237
:links="currAnchorLinks"
237238
:key="anchorRefreshKey"
238239
:is-affix="anchorAffix"
239240
type="dot"
240-
container-id="#doc-layout-scoller"
241+
container-id="#doc-layout-scroller"
241242
@link-click="handleAnchorClick"
242243
>
243244
</tiny-anchor>
@@ -469,7 +470,7 @@ export default defineComponent({
469470
const scrollByHash = (hash) => {
470471
setTimeout(() => {
471472
if (!hash) {
472-
document.getElementById('doc-layout-scoller').scrollTo({
473+
document.getElementById('doc-layout-scroller').scrollTo({
473474
top: 0,
474475
left: 0
475476
})
@@ -482,10 +483,10 @@ export default defineComponent({
482483
scrollTarget = document.querySelector(`#${hash}`)
483484
} catch (err) {}
484485
if (scrollTarget && !isRunningTest) {
485-
// doc-layout-scoller(滚动) > tabs > tab-content(relative), 造成 scrollTarget.offsetTop 是相对于 tab-content的距离
486+
// doc-layout-scroller(滚动) > tabs > tab-content(relative), 造成 scrollTarget.offsetTop 是相对于 tab-content的距离
486487
// 所以滚动需要修正 tab-title的占位高度才行
487-
document.getElementById('doc-layout-scoller').scrollTo({
488-
top: scrollTarget.offsetTop + 52,
488+
document.getElementById('doc-layout-scroller').scrollTo({
489+
top: scrollTarget.offsetTop,
489490
left: 0,
490491
behavior: 'smooth'
491492
})
@@ -499,7 +500,7 @@ export default defineComponent({
499500
let hash = router.currentRoute.value.hash?.slice(1)
500501
if (hash !== 'API') {
501502
setTimeout(() => {
502-
document.getElementById('doc-layout-scoller').scrollTo({
503+
document.getElementById('doc-layout-scroller').scrollTo({
503504
top: 0,
504505
left: 0,
505506
behavior: 'smooth'
@@ -620,26 +621,26 @@ export default defineComponent({
620621
}
621622
622623
const onDocLayoutScroll = debounce(100, false, () => {
623-
const docLayout = document.getElementById('doc-layout-scoller')
624+
const docLayout = document.getElementById('doc-layout-scroller')
624625
const { scrollTop, scrollHeight, clientHeight: layoutHeight } = docLayout
625626
const headerHeight = document.querySelector('.docs-header')?.clientHeight || 0
626627
const footerHeight = document.getElementById('footer')?.clientHeight || 0
627628
const anchorHeight = document.querySelector('#anchor')?.clientHeight || 0
628-
const remainHeight = scrollHeight - scrollTop - layoutHeight // doc-layout-scoller视口下隐藏的部分高度
629+
const remainHeight = scrollHeight - scrollTop - layoutHeight // doc-layout-scroller视口下隐藏的部分高度
629630
state.anchorAffix = layoutHeight - headerHeight - (footerHeight - remainHeight) > anchorHeight
630631
})
631632
632633
const setScrollListener = () => {
633634
nextTick(() => {
634-
const docLayout = document.getElementById('doc-layout-scoller')
635+
const docLayout = document.getElementById('doc-layout-scroller')
635636
if (docLayout) {
636637
docLayout.addEventListener('scroll', onDocLayoutScroll)
637638
}
638639
})
639640
}
640641
641642
const removeScrollListener = () => {
642-
const docLayout = document.getElementById('doc-layout-scoller')
643+
const docLayout = document.getElementById('doc-layout-scroller')
643644
if (docLayout) {
644645
docLayout.removeEventListener('scroll', onDocLayoutScroll)
645646
}
@@ -802,7 +803,7 @@ export default defineComponent({
802803
.docs-content {
803804
flex: 1;
804805
overflow: hidden auto;
805-
padding: 16px 0 0;
806+
margin-top: 16px;
806807
transition: all ease-in-out 0.3s;
807808
808809
.docs-tabs-wrap {
@@ -826,6 +827,7 @@ export default defineComponent({
826827
827828
:deep(> .tiny-tabs__header) {
828829
position: sticky;
830+
top: 0;
829831
z-index: var(--docs-tabs-header-zindex);
830832
background-color: #fff;
831833

examples/sites/src/views/components/float-settings.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export default defineComponent({
149149
150150
const funcs = {
151151
onBackTop() {
152-
document.getElementById('doc-layout').scrollTo({
152+
document.getElementById('doc-layout-scroller').scrollTo({
153153
top: 0,
154154
left: 0,
155155
behavior: 'smooth'
@@ -196,7 +196,7 @@ export default defineComponent({
196196
197197
const setScrollListener = () => {
198198
nextTick(() => {
199-
const docLayout = document.getElementById('doc-layout')
199+
const docLayout = document.getElementById('doc-layout-scroller')
200200
const nav = document.querySelector('.nav')
201201
if (docLayout) {
202202
docLayout.onscroll = debounce(100, false, () => {
@@ -218,7 +218,7 @@ export default defineComponent({
218218
}
219219
220220
const removeScrollListener = () => {
221-
const docLayout = document.getElementById('doc-layout') || {}
221+
const docLayout = document.getElementById('doc-layout-scroller') || {}
222222
docLayout.onscroll = null
223223
}
224224

0 commit comments

Comments
 (0)