Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
GeekLearnMathWeapp
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
frontend
GeekLearnMathWeapp
Commits
0f5a2097
Commit
0f5a2097
authored
Apr 04, 2023
by
hewenhao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: update
parent
adedecb8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
8 deletions
+32
-8
index.ts
src/hooks/index.ts
+1
-0
use-focus.ts
src/hooks/use-focus.ts
+16
-0
stage-tag.tsx
src/pages/main/components/scene/stage-tag.tsx
+15
-8
No files found.
src/hooks/index.ts
View file @
0f5a2097
...
...
@@ -3,3 +3,4 @@ export * from './use-countdown'
export
*
from
'./use-format-tick'
export
*
from
'./use-request'
export
*
from
'./use-toggle'
export
*
from
'./use-focus'
src/hooks/use-focus.ts
0 → 100644
View file @
0f5a2097
import
{
useState
}
from
'react'
import
{
useDidHide
,
useDidShow
}
from
'@tarojs/taro'
export
function
useFocus
()
{
const
[
isFocus
,
setIsFocus
]
=
useState
(
true
)
useDidHide
(()
=>
{
setIsFocus
(
false
)
})
useDidShow
(()
=>
{
setIsFocus
(
true
)
})
return
isFocus
}
src/pages/main/components/scene/stage-tag.tsx
View file @
0f5a2097
import
{
Image
}
from
'@tarojs/components'
import
{
useEffect
,
useRef
,
useMemo
}
from
'react'
import
{
useEffect
,
useRef
,
useMemo
,
useState
}
from
'react'
import
assets
from
'@/assets/oss/assets-round'
import
{
useFocus
}
from
'@/hooks'
import
{
usePageScroll
,
createIntersectionObserver
,
getCurrentInstance
,
getMenuButtonBoundingClientRect
,
IntersectionObserver
,
nextTick
}
from
'@tarojs/taro'
type
StageTagProps
=
{
...
...
@@ -11,27 +12,33 @@ type StageTagProps = {
}
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
)
usePageScroll
(
payload
=>
{
scrollRef
.
current
=
payload
.
scrollTop
})
useEffect
(()
=>
{
setIsAnimated
(
false
)
},
[
url
])
const
uid
=
useMemo
(()
=>
`tag_
${
id
}
`
,
[
id
])
const
bgid
=
useMemo
(()
=>
`bg_
${
id
}
`
,
[
id
])
useEffect
(()
=>
{
let
observer
:
IntersectionObserver
|
null
=
null
const
fn
=
()
=>
{
if
(
ready
)
{
console
.
log
(
ready
,
isFocus
,
111
)
if
(
ready
&&
isFocus
)
{
const
navVal
=
nav
.
current
// @ts-ignore
observer
=
createIntersectionObserver
()
let
isAnimated
=
false
const
animateBg
=
()
=>
{
const
page
=
getCurrentInstance
().
page
page
?.
animate
?.(
`#
${
bgid
}
`
,
[
{
opacity
:
1
},
{
opacity
:
0
},
...
...
@@ -51,8 +58,8 @@ const StageTag = (props: StageTagProps) => {
clearTimeout
(
timer
)
}
timer
=
setTimeout
(()
=>
{
isAnimated
=
true
getCurrentInstance
().
page
?.
animate
?.(
`#
${
uid
}
`
,
[
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
},
...
...
@@ -71,7 +78,7 @@ const StageTag = (props: StageTagProps) => {
clearTimeout
(
timer
)
}
timer
=
setTimeout
(()
=>
{
isAnimated
=
true
setIsAnimated
(
true
)
animateBg
()
},
900
)
}
...
...
@@ -88,7 +95,7 @@ const StageTag = (props: StageTagProps) => {
observer
=
null
}
}
},
[
uid
,
ready
,
bgid
,
url
])
},
[
uid
,
ready
,
bgid
,
url
,
page
,
isFocus
,
isAnimated
])
if
(
!
ready
)
{
return
null
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment