hookehuyr

feat(HomePage): 添加内容区域滚动重置功能

在切换标签时,重置内容区域的位置,确保用户无需手动滚动即可看到新内容
1 <!-- 1 <!--
2 * @Date: 2025-03-20 19:55:21 2 * @Date: 2025-03-20 19:55:21
3 * @LastEditors: hookehuyr hookehuyr@gmail.com 3 * @LastEditors: hookehuyr hookehuyr@gmail.com
4 - * @LastEditTime: 2025-03-25 16:44:51 4 + * @LastEditTime: 2025-03-25 17:48:53
5 * @FilePath: /mlaj/src/views/HomePage.vue 5 * @FilePath: /mlaj/src/views/HomePage.vue
6 * @Description: 亲子学院首页组件 6 * @Description: 亲子学院首页组件
7 * 7 *
...@@ -282,7 +282,7 @@ ...@@ -282,7 +282,7 @@
282 </div> 282 </div>
283 283
284 <!-- Content Based on Active Tab --> 284 <!-- Content Based on Active Tab -->
285 - <div class="px-4 mt-5"> 285 + <div class="px-4 mt-5" ref="contentRef">
286 <!-- Recommended Content --> 286 <!-- Recommended Content -->
287 <div v-if="activeTab === '推荐'"> 287 <div v-if="activeTab === '推荐'">
288 <!-- Personalized Recommendations --> 288 <!-- Personalized Recommendations -->
...@@ -674,4 +674,18 @@ onUnmounted(() => { ...@@ -674,4 +674,18 @@ onUnmounted(() => {
674 clearInterval(carouselInterval) 674 clearInterval(carouselInterval)
675 } 675 }
676 }) 676 })
677 +
678 +const contentRef = ref(null) // 内容区域的ref引用
679 +
680 +// 监听activeTab变化,重置内容区域位置
681 +watch(activeTab, () => {
682 + if (contentRef.value) {
683 + const navHeight = document.querySelector('.sticky').offsetHeight;
684 + const marginTop = parseInt(window.getComputedStyle(contentRef.value).marginTop);
685 + window.scrollTo({
686 + top: contentRef.value.offsetTop - navHeight - marginTop,
687 + behavior: 'smooth'
688 + });
689 + }
690 +})
677 </script> 691 </script>
......