Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
web2022
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Website
web2022
Commits
0dc68015
Commit
0dc68015
authored
Aug 03, 2022
by
mxm-web-develop
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
321
parent
c8f258dd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
17 deletions
+13
-17
ScrollView.tsx
src/components/ScrollView.tsx
+13
-17
No files found.
src/components/ScrollView.tsx
View file @
0dc68015
...
...
@@ -8,7 +8,7 @@ import ScrollBar from "@better-scroll/scroll-bar";
import
Slide
from
"@better-scroll/slide"
;
import
NestedScroll
from
'@better-scroll/nested-scroll'
import
ContactImg
from
'@/assets/img/contact.png'
import
{
debounce
as
_debounce
}
from
'lodash'
import
{
useCallback
,
useContext
,
useEffect
,
useMemo
,
useRef
,
useState
}
from
"react"
;
import
{
LazyImg
}
from
"./LazyImg"
;
import
{
useLocation
}
from
"react-router-dom"
;
...
...
@@ -78,7 +78,7 @@ export const ScrollView = (props: ScrollViewType) => {
BScroll
.
use
(
ScrollBar
);
BScroll
.
use
(
Slide
);
BScroll
.
use
(
NestedScroll
)
const
{
wrapHeight
,
children
}
=
props
;
const
{
children
}
=
props
;
const
wrapRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
location
=
useLocation
()
const
[
dots
,
setDots
]
=
useState
(
0
)
...
...
@@ -86,48 +86,44 @@ export const ScrollView = (props: ScrollViewType) => {
const
[
currentPage
,
setCurrentPage
]
=
useState
(
0
)
const
{
data
,
dispatch
}
=
useContext
(
AppContext
)
useEffect
(()
=>
{
dispatch
({
type
:
'doSome'
})
},[])
useEffect
(()
=>
{
useEffect
(()
=>
{
const
scrollEl
=
initBScroll
(
wrapRef
.
current
as
HTMLDivElement
)
setScrollObj
(
scrollEl
)
return
()
=>
{
scroll
Obj
?
.
destroy
();
scroll
El
.
destroy
();
};
},[
wrapRef
])
useEffect
(()
=>
{
setDots
(
children
&&
children
.
props
.
children
.
length
)
},
[]);
useEffect
(()
=>
{
const
page
=
scrollObj
?.
plugins
[
'slide'
].
pages
.
currentPage
page
&&
setCurrentPage
((
prevState
:
number
)
=>
{
const
page
=
scrollObj
&&
scrollObj
.
plugins
[
'slide'
].
pages
.
currentPage
page
&&
setCurrentPage
((
prevState
:
number
)
=>
{
if
(
prevState
!==
page
.
pageY
){
return
page
.
pageY
}
return
prevState
})
scrollObj
?.
on
(
'slidePageChanged'
,
(
page
:
any
)
=>
{
const
data
=
{
page
:
page
.
pageY
,
}
scrollObj
&&
scrollObj
.
on
(
'slidePageChanged'
,
(
page
:
any
)
=>
{
console
.
log
(
'slidePageChanged'
,
2332131231
);
setCurrentPage
((
prevState
:
number
)
=>
{
if
(
prevState
!==
page
.
pageY
){
return
page
.
pageY
dispatch
({
type
:
'slideOnChange'
,
payload
:{
pageIndex
:
page
.
pageY
}})
return
page
.
pageY
}
return
prevState
})
})
},[
scrollObj
])
const
pageMoving
=
(
index
:
number
)
=>
{
if
(
index
!==
currentPage
){
scrollObj
?.
goToPage
(
0
,
index
,
600
)
}
return
}
return
(
<
div
className=
"slide-vertical h-screen w-screen "
...
...
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