Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
jinfa-platform
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
shenshaokai
jinfa-platform
Commits
991b7a6f
Commit
991b7a6f
authored
Mar 01, 2021
by
前端-钟卫鹏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 优化滑动跳转效果
parent
aafd9e85
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
50 deletions
+26
-50
index.tsx
src/pages/procurement/components/bidDetailHeader/index.tsx
+20
-36
index.tsx
src/pages/procurement/components/bidMaterial/index.tsx
+6
-14
No files found.
src/pages/procurement/components/bidDetailHeader/index.tsx
View file @
991b7a6f
...
...
@@ -32,9 +32,7 @@ const BidDetailHeader:React.FC<BidDetailHeaderProps> = ({
const
[
current
,
setCurrent
]
=
useState
<
number
>
(
0
)
const
[
isFixed
,
setIsFixed
]
=
useState
<
boolean
>
(
false
)
useEffect
(()
=>
{
// window.addEventListener("scroll", debounce(onScroll, 500));
window
.
addEventListener
(
"scroll"
,
onScroll
)
return
(()
=>
{
window
.
removeEventListener
(
'scroll'
,
onScroll
)
...
...
@@ -49,50 +47,36 @@ const BidDetailHeader:React.FC<BidDetailHeaderProps> = ({
setCurrent
(
index
)
}
})
// // @todo 不使用防抖情况下 焦点会出现抖动;使用防抖,固定头部会延迟或者无效
// // 锚点导航距离顶端距离
// let navDom: any = document.getElementById("anchorTitle")
// if(navDom) {
// let distance = navDom.offsetTop - document.documentElement.scrollTop
// if(!flagRef.current.flag) {
// flagRef.current.distanceTop = navDom.offsetTop
// flagRef.current.flag = true
// }
// 锚点导航距离顶端距离
let
navDom
:
any
=
document
.
getElementById
(
"anchorTitle"
)
if
(
navDom
)
{
let
distance
=
navDom
.
offsetTop
-
document
.
documentElement
.
scrollTop
if
(
!
flagRef
.
current
.
flag
)
{
flagRef
.
current
.
distanceTop
=
navDom
.
offsetTop
flagRef
.
current
.
flag
=
true
}
//
if(distance <= 0) {
//
setIsFixed(true)
//
}
if
(
distance
<=
0
)
{
setIsFixed
(
true
)
}
//
if(document.documentElement.scrollTop <= flagRef.current.distanceTop) {
//
setIsFixed(false)
//
}
//
}
if
(
document
.
documentElement
.
scrollTop
<=
flagRef
.
current
.
distanceTop
)
{
setIsFixed
(
false
)
}
}
}
const
clickItem
=
(
index
:
any
)
=>
{
setCurrent
(
index
)
console
.
log
(
formContext
.
offsetTopList
,
'context'
,
formContext
.
offsetTopList
[
index
])
let
distance
=
formContext
.
offsetTopList
[
index
]
-
140
window
.
scrollTo
({
top
:
distance
<
0
?
0
:
distance
,
behavior
:
"smooth"
});
if
(
index
>
0
)
setIsFixed
(
true
)
else
setIsFixed
(
false
)
})
let
dom
=
document
.
documentElement
||
document
.
body
if
(
formContext
.
offsetTopList
[
index
]
-
189
+
dom
.
clientHeight
>=
dom
.
scrollHeight
)
{
setCurrent
(
index
)
}
}
// // 简单的防抖动函数
// const debounce = (func, wait, immediate?) => {
// // setIsFixed(true)
// // 定时器变量
// let timeout;
// return () => {
// // 每次触发 scroll handler 时先清除定时器
// clearTimeout(timeout);
// // 指定 xx ms 后触发真正想进行的操作 handler
// timeout = setTimeout(func, wait);
// };
// }
return
(
<
div
className=
{
isFixed
?
[
style
.
detailHeader
,
style
.
anchorTitleFixed
].
join
(
' '
):
style
.
detailHeader
}
id=
"detailHeader"
>
...
...
src/pages/procurement/components/bidMaterial/index.tsx
View file @
991b7a6f
...
...
@@ -40,18 +40,6 @@ const BidMaterial: React.FC<BidMaterialProps> = ({cardTitle}) => {
const
titleMap
=
[
'基本信息'
,
'产地'
,
'外观尺寸'
,
'工艺'
,
'特殊说明'
,
'附件'
,
'采购数量'
]
// // 简单的防抖动函数
// const debounce = (func, wait, immediate?) => {
// // 定时器变量
// let timeout;
// return () => {
// // 每次触发 scroll handler 时先清除定时器
// clearTimeout(timeout);
// // 指定 xx ms 后触发真正想进行的操作 handler
// timeout = setTimeout(func, wait);
// };
// }
const
onScroll
=
(
e
)
=>
{
if
(
e
.
target
.
className
===
'ant-drawer-body'
)
{
let
scrollTop
=
document
.
querySelectorAll
(
".ant-drawer-body"
)[
0
].
scrollTop
...
...
@@ -121,11 +109,15 @@ const BidMaterial: React.FC<BidMaterialProps> = ({cardTitle}) => {
}
const
handleClick
=
(
i
:
number
)
=>
{
setCurrent
(
i
)
do
cument
.
querySelectorAll
(
".ant-drawer-body"
)[
0
]
.
scroll
({
let
dom
=
document
.
querySelectorAll
(
".ant-drawer-body"
)[
0
]
do
m
.
scroll
({
'top'
:
offsetTopList
[
i
]
-
16
,
behavior
:
"smooth"
,
})
// scrollTop + clientHeight == scrollHeight
if
(
offsetTopList
[
i
]
+
dom
.
clientHeight
>=
dom
.
scrollHeight
)
{
setCurrent
(
i
)
}
}
return
(<>
...
...
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