Commit 0af1923d authored by hewenhao's avatar hewenhao

feat: update

parent e46903f7
......@@ -4,11 +4,21 @@ import assets from '@/assets/oss/assets-round'
import { useFocus } from '@/hooks'
import {
usePageScroll, createIntersectionObserver, getCurrentInstance,
getMenuButtonBoundingClientRect, IntersectionObserver, nextTick
getMenuButtonBoundingClientRect, IntersectionObserver, nextTick,
createInnerAudioContext
} from '@tarojs/taro'
import { palyAudio } from '@/utils/play-audio'
import audio from '@/assets/oss/assets-audio'
function palyAudio (src: string) {
// @ts-ignore
const innerAudioContext = createInnerAudioContext({ useWebAudioImplement: true })
innerAudioContext.src = src
innerAudioContext.play()
innerAudioContext.onEnded = () => {
innerAudioContext.destroy()
}
}
type StageTagProps = {
url?: string;
className: string;
......@@ -16,11 +26,28 @@ type StageTagProps = {
ready: boolean;
}
const animationQueue: (() => void)[] = []
let isAnimating = false
function flushQueue () {
if (isAnimating) {
return
}
const fn = animationQueue.shift()
if (fn) {
isAnimating = true
setTimeout(() => {
fn()
isAnimating = false
flushQueue()
}, 300)
}
}
const StageTag = (props: StageTagProps) => {
const page = useMemo(() => getCurrentInstance().page, [])
const nav = useRef(getMenuButtonBoundingClientRect())
const { url, className, id, ready } = props
const [isAnimated, setIsAnimated] = useState(false)
const isFocus = useFocus()
const scrollRef = useRef(0)
......@@ -28,10 +55,6 @@ const StageTag = (props: StageTagProps) => {
scrollRef.current = payload.scrollTop
})
useEffect(() => {
setIsAnimated(false)
}, [url])
const uid = useMemo(() => `tag_${id}`, [id])
useEffect(() => {
......@@ -41,26 +64,25 @@ const StageTag = (props: StageTagProps) => {
const navVal = nav.current
// @ts-ignore
observer = createIntersectionObserver()
let timer: NodeJS.Timeout | null = null
if (url) {
observer
.relativeToViewport({ bottom: 0, top: -navVal.height - navVal.top - 5 - 50 })
.observe(`#${uid}`, ({ intersectionRatio }) => {
if (intersectionRatio > 0) {
if (isAnimated) return
if (timer) {
clearTimeout(timer)
}
timer = setTimeout(() => {
animationQueue.push(() => {
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, () => {})
}, 500)
if (observer) {
observer.disconnect()
observer = null
}
})
flushQueue()
}
})
}
......@@ -75,7 +97,7 @@ const StageTag = (props: StageTagProps) => {
observer = null
}
}
}, [uid, ready, url, page, isFocus, isAnimated])
}, [uid, ready, url, page, isFocus])
if (!ready) {
return null
......
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