Commit 583aed3c authored by hewenhao's avatar hewenhao

feat: 首页优化

parent 8b8e29b4
...@@ -2,12 +2,14 @@ import { Image } from '@tarojs/components' ...@@ -2,12 +2,14 @@ import { Image } from '@tarojs/components'
import { useEffect, useRef, useMemo, useState } from 'react' import { useEffect, useRef, useMemo, useState } from 'react'
import assets from '@/assets/oss/assets-round' import assets from '@/assets/oss/assets-round'
import { useFocus } from '@/hooks' import { useFocus } from '@/hooks'
import classNames from 'classnames'
import { import {
usePageScroll, createIntersectionObserver, getCurrentInstance, usePageScroll, createIntersectionObserver, getCurrentInstance,
getMenuButtonBoundingClientRect, IntersectionObserver, nextTick, getMenuButtonBoundingClientRect, IntersectionObserver, nextTick,
createInnerAudioContext, onAppHide, onAppShow createInnerAudioContext, onAppHide, onAppShow
} from '@tarojs/taro' } from '@tarojs/taro'
import audio from '@/assets/oss/assets-audio' import audio from '@/assets/oss/assets-audio'
import styles from './stage.module.scss'
let isHide = false let isHide = false
...@@ -76,31 +78,39 @@ const StageTag = (props: StageTagProps) => { ...@@ -76,31 +78,39 @@ const StageTag = (props: StageTagProps) => {
useEffect(() => { useEffect(() => {
let observer: IntersectionObserver | null = null let observer: IntersectionObserver | null = null
if (isAnimated) return if (isAnimated) return
const animateFn = () => {
palyAudio(audio['蹦蹦top出现首页.wav'].u)
setIsAnimated(true)
page?.animate?.(`#${uid}`, [
{ opacity: 0, translateY: 50, scale: [1, 1] },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.5 },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.75 },
{ opacity: 1, translateY: 0, scale: [1, 1] },
], 1000, () => {})
if (observer) {
observer.disconnect()
observer = null
}
}
const fn = () => { const fn = () => {
if (ready && isFocus) { if (ready && isFocus) {
const navVal = nav.current const navVal = nav.current
// @ts-ignore
observer = createIntersectionObserver()
if (url) { if (url) {
// @ts-ignore
observer = createIntersectionObserver()
observer observer
.relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 }) .relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 })
.observe(`#${uid}`, ({ intersectionRatio }) => { .observe(`#${uid}`, ({ intersectionRatio }) => {
if (intersectionRatio > 0) { if (intersectionRatio > 0) {
animationQueue.push(() => { animationQueue.push(animateFn)
palyAudio(audio['蹦蹦top出现首页.wav'].u)
setIsAnimated(true)
page?.animate?.(`#${uid}`, [
{ opacity: 0, translateY: 50, scale: [1, 1] },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.5 },
{ opacity: 1, translateY: -20, scale: [1.5, 1.5], offset: 0.75 },
{ opacity: 1, translateY: 0, scale: [1, 1] },
], 1000, () => {})
if (observer) {
observer.disconnect()
observer = null
}
})
flushQueue() flushQueue()
} else if (!isAnimated) { // 隐藏了 还没有显示动画 就移除队列
const index = animationQueue.indexOf(animateFn)
if (index !== -1) {
animationQueue.splice(index, 1)
}
} }
}) })
} }
...@@ -126,7 +136,7 @@ const StageTag = (props: StageTagProps) => { ...@@ -126,7 +136,7 @@ const StageTag = (props: StageTagProps) => {
{url && ( {url && (
<Image src={url} className={className} style={{ opacity: 0 }} id={uid}></Image> <Image src={url} className={className} style={{ opacity: 0 }} id={uid}></Image>
)} )}
<Image src={assets['top-bg.png'].u} className={className}></Image> <Image src={assets['top-bg.png'].u} className={classNames(className, styles.top_bg)}></Image>
</> </>
) )
} }
......
...@@ -50,6 +50,23 @@ ...@@ -50,6 +50,23 @@
height: 28px; height: 28px;
} }
.top_bg {
animation-name: fadeIn;
animation-duration: 1s;
animation-timing-function: ease-out;
animation-fill-mode: backwards;
animation-iteration-count: 1;
}
@keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
.uparrow { .uparrow {
position: absolute; position: absolute;
z-index: 3; z-index: 3;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment