feat: auto-scroll to content below when search page mode is activated

This commit is contained in:
Hakadao
2023-10-17 11:05:30 +08:00
parent 6d4eee744d
commit d59d78e3d5
5 changed files with 14 additions and 12 deletions

View File

@@ -222,10 +222,10 @@ function handleRefresh() {
dynamicComponentKey.value = `dynamicComponent${Number(new Date())}`
}
function handleBackToTop() {
function handleBackToTop(targetScrollTop = 0 as number) {
const osInstance = scrollbarRef.value?.osInstance()
smoothScrollToTop(osInstance.elements().viewport, 300)
smoothScrollToTop(osInstance.elements().viewport, 300, targetScrollTop)
}
function handleAdaptToOtherPageStylesChange() {

View File

@@ -8,7 +8,7 @@ import { HomeSubPage } from './types'
import emitter from '~/utils/mitt'
import { settings } from '~/logic'
const handleBackToTop = inject('handleBackToTop') as () => void
const handleBackToTop = inject('handleBackToTop') as (targetScrollTop: number) => void
const recommendContentKey = ref<string>(`recommendContent${Number(new Date())}`)
const activatedPage = ref<HomeSubPage>(HomeSubPage.ForYou)
@@ -34,7 +34,7 @@ const tabs = reactive<HomeTab[]>([
])
watch(() => activatedPage.value, () => {
handleBackToTop()
handleBackToTop(settings.value.useSearchPageModeOnHomePage ? 510 : 0)
})
onMounted(() => {
@@ -57,6 +57,7 @@ onUnmounted(() => {
>
<div
pos="absolute left-0 top-0" w-full h-580px mb--580px bg="cover center" z-1
pointer-events-none
:style="{
backgroundImage: `url(${settings.searchPageWallpaper})`,
backgroundAttachment: settings.searchPageModeWallpaperFixed ? 'fixed' : 'unset'

View File

@@ -7,7 +7,7 @@ import { LanguageType } from '~/enums/appEnums'
const videoList = reactive<ForYouVideoModel[]>([])
const appVideoList = reactive<AppForYouVideoModel[]>([])
const isLoading = ref<boolean>(false)
const isLoading = ref<boolean>(true)
const needToLoginFirst = ref<boolean>(false)
const containerRef = ref<HTMLElement>() as Ref<HTMLElement>
const refreshIdx = ref<number>(1)

View File

@@ -1,10 +1,11 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import type { RankingType, RankingVideoModel } from '../types'
import { settings } from '~/logic'
const { t } = useI18n()
const handleBackToTop = inject('handleBackToTop') as () => void
const handleBackToTop = inject('handleBackToTop') as (targetScrollTop: number) => void
const rankingTypes = computed((): RankingType[] => {
return [
@@ -41,7 +42,7 @@ const activatedRankingType = reactive<RankingType>({ ...rankingTypes.value[0] })
const videoList = reactive<RankingVideoModel[]>([])
watch(() => activatedRankingType.name, () => {
handleBackToTop()
handleBackToTop(settings.value.useSearchPageModeOnHomePage ? 510 : 0)
getRankingVideos()
})