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
5d1919fb
Commit
5d1919fb
authored
Aug 04, 2022
by
louyuqi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
scroll
parent
738b691f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
13 deletions
+29
-13
NewsScrollView.tsx
src/components/NewsScrollView.tsx
+28
-12
index.tsx
src/views/News/index.tsx
+1
-1
No files found.
src/components/NewsScrollView.tsx
View file @
5d1919fb
import
{
useAsyncState
}
from
"@/common/hooks"
;
import
{
IProps
}
from
"@/common/Iprops.interface"
;
import
{
useAsyncState
}
from
"@/common/hooks"
;
import
{
IProps
}
from
"@/common/Iprops.interface"
;
import
BScroll
from
"@better-scroll/core"
;
import
{
BScrollConstructor
}
from
"@better-scroll/core/dist/types/BScroll"
;
import
{
BScrollConstructor
}
from
"@better-scroll/core/dist/types/BScroll"
;
import
MouseWheel
from
"@better-scroll/mouse-wheel"
;
import
ScrollBar
from
"@better-scroll/scroll-bar"
;
import
ObserveDOM
from
'@better-scroll/observe-dom'
import
Pullup
from
'@better-scroll/pull-up'
import
{
ForwardedRef
,
forwardRef
,
ForwardRefRenderFunction
,
useCallback
,
useEffect
,
useMemo
,
useRef
,
useState
}
from
"react"
;
import
{
ForwardedRef
,
forwardRef
,
ForwardRefRenderFunction
,
useCallback
,
useEffect
,
useMemo
,
useRef
,
useState
}
from
"react"
;
interface
ScrollViewType
extends
IProps
{
wrapHeight
?:
string
;
prop
?:
any
;
}
const
initBScroll
=
(
el
:
HTMLElement
)
=>
{
const
initBScroll
=
(
el
:
HTMLElement
)
=>
{
const
res
=
new
BScroll
(
el
,
{
click
:
true
,
mouseWheel
:
{
...
...
@@ -21,12 +31,13 @@ const initBScroll = (el:HTMLElement) => {
easeTime
:
300
,
},
pullUpLoad
:
{
threshold
:
2
00
threshold
:
1
00
},
observeDOM
:
true
,
probeType
:
2
,
probeType
:
2
,
// 显示滚动条,
useTransition
:
true
,
useTransition
:
true
,
scrollX
:
false
,
momentum
:
true
,
scrollY
:
true
,
...
...
@@ -41,21 +52,26 @@ export const NewsScrollView = (props: ScrollViewType) => {
BScroll
.
use
(
MouseWheel
);
BScroll
.
use
(
Pullup
)
BScroll
.
use
(
ObserveDOM
);
const
{
wrapHeight
,
children
}
=
props
;
const
{
wrapHeight
,
children
}
=
props
;
const
wrapRef
=
useRef
<
HTMLDivElement
>
(
null
);
const
[
scrollObj
,
setScrollObj
]
=
useState
<
BScrollConstructor
<
{}
>>
();
useEffect
(()
=>
{
useEffect
(()
=>
{
const
scrollEl
=
initBScroll
(
wrapRef
.
current
as
HTMLDivElement
)
// scrollEl.minScrollY=0
setScrollObj
(
scrollEl
)
// scrollEl.on('scroll',()=>{
// scrollEl.minScrollY=0
// })
return
()
=>
{
scrollObj
?.
destroy
();
};
},[
wrapRef
])
},
[
wrapRef
])
return
(
<
div
className=
" h-full overflow-hidden pb-5 -translate-x-[
200px]"
ref=
{
wrapRef
}
>
<
div
className=
" h-full overflow-hidden pb-5 ml-[-
200px]"
ref=
{
wrapRef
}
>
{
children
}
...
...
src/views/News/index.tsx
View file @
5d1919fb
...
...
@@ -60,7 +60,7 @@ export default function News(props: IAppProps) {
</
div
>
</
div
>
</
div
>
<
div
className=
"right h-full pt-28 w-7/12 relative"
>
<
div
className=
"right h-full pt-28 w-7/12 relative"
style=
{
{
boxSizing
:
"border-box"
}
}
>
<
NewsScrollView
>
<
div
className=
'mb-12 pb-[200px]'
>
<
ul
className=
"news-list -translate-x-[25px]"
>
...
...
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