Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SMU-GDMU-CHINA
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
2024 Competition
SMU-GDMU-CHINA
Commits
0a894718
Commit
0a894718
authored
5 months ago
by
Yifeng Wang
Browse files
Options
Downloads
Patches
Plain Diff
all
parent
27189f3b
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/components/Navbar copy.tsx
+94
-0
94 additions, 0 deletions
src/components/Navbar copy.tsx
src/components/Navbar.css
+2
-2
2 additions, 2 deletions
src/components/Navbar.css
src/components/Navbar.tsx
+9
-10
9 additions, 10 deletions
src/components/Navbar.tsx
with
105 additions
and
12 deletions
src/components/Navbar copy.tsx
0 → 100644
+
94
−
0
View file @
0a894718
import
{
useState
,
useEffect
}
from
"
react
"
;
import
Nav
from
"
react-bootstrap/Nav
"
;
import
BootstrapNavbar
from
"
react-bootstrap/Navbar
"
;
import
NavDropdown
from
"
react-bootstrap/NavDropdown
"
;
import
{
Link
,
useLocation
}
from
"
react-router-dom
"
;
import
Pages
from
"
../pages.ts
"
;
import
{
Container
}
from
"
react-bootstrap
"
;
import
"
./Navbar.css
"
;
export
function
Navbar
()
{
const
[
scrollProgress
,
setScrollProgress
]
=
useState
(
0
);
const
location
=
useLocation
();
useEffect
(()
=>
{
const
handleScroll
=
()
=>
{
const
totalScroll
=
document
.
documentElement
.
scrollHeight
-
window
.
innerHeight
;
const
currentScroll
=
window
.
pageYOffset
;
const
scrollPercentage
=
(
currentScroll
/
totalScroll
)
*
100
;
setScrollProgress
(
scrollPercentage
);
};
if
(
location
.
pathname
===
"
/
"
)
{
window
.
addEventListener
(
"
scroll
"
,
handleScroll
);
handleScroll
();
// 初始化进度
}
return
()
=>
{
window
.
removeEventListener
(
"
scroll
"
,
handleScroll
);
};
},
[
location
]);
const
pages
=
Pages
.
map
((
item
,
pageIndex
)
=>
{
if
(
"
folder
"
in
item
&&
item
.
folder
)
{
const
folderItems
=
item
.
folder
.
map
((
subpage
,
subpageIndex
)
=>
{
if
(
subpage
.
path
)
{
const
SubpageIcon
=
subpage
.
icon
;
// 获取子页面图标
return
(
<
NavDropdown
.
Item
key
=
{
`subpage-
${
pageIndex
}
-
${
subpageIndex
}
`
}
as
=
{
Link
}
to
=
{
subpage
.
path
}
className
=
"custom-dropdown-menu"
>
{
SubpageIcon
&&
<
SubpageIcon
/>
}
{
subpage
.
name
}
{
/* 添加图标 */
}
</
NavDropdown
.
Item
>
);
}
});
const
ItemIcon
=
item
.
icon
;
// 获取文件夹图标
return
(
<
NavDropdown
key
=
{
`page-
${
pageIndex
}
`
}
title
=
{
<>
{
ItemIcon
&&
<
ItemIcon
/>
}
{
item
.
name
}
</>
}
// 添加图标
id
=
"basic-nav-dropdown"
className
=
"custom-dropdown-menu"
>
{
folderItems
}
</
NavDropdown
>
);
}
else
if
(
"
path
"
in
item
&&
item
.
path
)
{
const
ItemIcon
=
item
.
icon
;
// 获取页面图标
return
(
<
Nav
.
Link
key
=
{
`page-
${
pageIndex
}
`
}
as
=
{
Link
}
to
=
{
item
.
path
}
className
=
"custom-dropdown-menu"
>
{
ItemIcon
&&
<
ItemIcon
/>
}
{
item
.
name
}
{
/* 添加图标 */
}
</
Nav
.
Link
>
);
}
});
return
(
<>
<
BootstrapNavbar
expand
=
"lg"
className
=
"apple-navbar"
fixed
=
"top"
>
<
Container
fluid
>
<
Link
to
=
"/"
className
=
"apple-brand"
>
<
img
src
=
"https://static.igem.wiki/teams/5378/school-badge/liverbrainguardian.webp"
className
=
"apple-logo"
alt
=
"Logo"
/>
</
Link
>
<
BootstrapNavbar
.
Toggle
aria-controls
=
"basic-navbar-nav"
className
=
"apple-toggler"
/>
<
BootstrapNavbar
.
Collapse
id
=
"basic-navbar-nav"
>
<
Nav
className
=
"ms-auto apple-nav"
>
{
pages
}
</
Nav
>
</
BootstrapNavbar
.
Collapse
>
</
Container
>
</
BootstrapNavbar
>
{
location
.
pathname
===
"
/
"
&&
(
<
div
className
=
"scroll-progress-bar"
style
=
{
{
width
:
`
${
scrollProgress
}
%`
}
}
></
div
>
)
}
</>
);
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
src/components/Navbar.css
+
2
−
2
View file @
0a894718
...
@@ -68,8 +68,8 @@
...
@@ -68,8 +68,8 @@
position
:
fixed
;
position
:
fixed
;
top
:
68px
;
/* 调整这个值以匹配你的导航栏高度 */
top
:
68px
;
/* 调整这个值以匹配你的导航栏高度 */
left
:
0
;
left
:
0
;
height
:
3
px
;
height
:
7
px
;
background-color
:
#
007af
f
;
/* 使用 Apple 风格的蓝色 */
background-color
:
#
d9534
f
;
/* 使用 Apple 风格的蓝色 */
z-index
:
1000
;
z-index
:
1000
;
transition
:
width
0.1s
ease-out
;
transition
:
width
0.1s
ease-out
;
}
}
...
...
This diff is collapsed.
Click to expand it.
src/components/Navbar.tsx
+
9
−
10
View file @
0a894718
...
@@ -11,6 +11,8 @@ export function Navbar() {
...
@@ -11,6 +11,8 @@ export function Navbar() {
const
[
scrollProgress
,
setScrollProgress
]
=
useState
(
0
);
const
[
scrollProgress
,
setScrollProgress
]
=
useState
(
0
);
const
location
=
useLocation
();
const
location
=
useLocation
();
useEffect
(()
=>
{
useEffect
(()
=>
{
const
handleScroll
=
()
=>
{
const
handleScroll
=
()
=>
{
const
totalScroll
=
document
.
documentElement
.
scrollHeight
-
window
.
innerHeight
;
const
totalScroll
=
document
.
documentElement
.
scrollHeight
-
window
.
innerHeight
;
...
@@ -19,10 +21,9 @@ export function Navbar() {
...
@@ -19,10 +21,9 @@ export function Navbar() {
setScrollProgress
(
scrollPercentage
);
setScrollProgress
(
scrollPercentage
);
};
};
if
(
location
.
pathname
===
"
/
"
)
{
// Remove the condition for the home page
window
.
addEventListener
(
"
scroll
"
,
handleScroll
);
window
.
addEventListener
(
"
scroll
"
,
handleScroll
);
handleScroll
();
// 初始化进度
handleScroll
();
// Initialize progress
}
return
()
=>
{
return
()
=>
{
window
.
removeEventListener
(
"
scroll
"
,
handleScroll
);
window
.
removeEventListener
(
"
scroll
"
,
handleScroll
);
...
@@ -83,12 +84,10 @@ export function Navbar() {
...
@@ -83,12 +84,10 @@ export function Navbar() {
</
BootstrapNavbar
.
Collapse
>
</
BootstrapNavbar
.
Collapse
>
</
Container
>
</
Container
>
</
BootstrapNavbar
>
</
BootstrapNavbar
>
{
location
.
pathname
===
"
/
"
&&
(
<
div
<
div
className
=
"scroll-progress-bar"
className
=
"scroll-progress-bar"
style
=
{
{
width
:
`
${
scrollProgress
}
%`
}
}
style
=
{
{
width
:
`
${
scrollProgress
}
%`
}
}
></
div
>
></
div
>
)
}
</>
</>
);
);
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment