Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tsinghua
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
Package Registry
Model registry
Operate
Terraform modules
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
Zhefu Li
Tsinghua
Commits
df11cc37
Commit
df11cc37
authored
5 months ago
by
HouTeng Chan
Browse files
Options
Downloads
Patches
Plain Diff
Update file menu.html
parent
814ed39d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
wiki/menu.html
+69
-54
69 additions, 54 deletions
wiki/menu.html
with
69 additions
and
54 deletions
wiki/menu.html
+
69
−
54
View file @
df11cc37
...
...
@@ -206,81 +206,96 @@
</nav>
<script>
function
toggleMenu
(){
var
navbar
=
document
.
getElementById
(
'
my-navbar
'
);
navbar
.
classList
.
toggle
(
'
show-menu
'
);
}
document
.
addEventListener
(
'
DOMContentLoaded
'
,
function
()
{
function
toggleMenu
(){
var
navbar
=
document
.
getElementById
(
'
my-navbar
'
);
navbar
.
classList
.
toggle
(
'
show-menu
'
);
}
var
navItems
=
document
.
querySelectorAll
(
'
.my-navbar > li
'
);
var
navItems
=
document
.
querySelectorAll
(
'
.my-navbar > li
'
);
navItems
.
forEach
(
function
(
item
){
item
.
addEventListener
(
'
click
'
,
function
(
e
){
if
(
window
.
innerWidth
<=
768
){
if
(
this
.
querySelector
(
'
.son
'
)){
e
.
preventDefault
();
this
.
classList
.
toggle
(
'
show
'
);
}
navItems
.
forEach
(
function
(
item
){
item
.
addEventListener
(
'
click
'
,
function
(
e
){
if
(
window
.
innerWidth
<=
768
){
if
(
this
.
querySelector
(
'
.son
'
)){
e
.
preventDefault
();
this
.
classList
.
toggle
(
'
show
'
);
}
}
);
}
});
});
document
.
addEventListener
(
'
click
'
,
function
(
e
){
// 新增:处理子菜单项的点击事件
var
subMenuItems
=
document
.
querySelectorAll
(
'
.son li a
'
);
subMenuItems
.
forEach
(
function
(
item
)
{
item
.
addEventListener
(
'
click
'
,
function
(
e
)
{
if
(
window
.
innerWidth
<=
768
){
var
navbar
=
document
.
getElementById
(
'
my-navbar
'
);
var
hamburger
=
document
.
querySelector
(
'
.hamburger
'
);
if
(
!
navbar
.
contains
(
e
.
target
)
&&
e
.
target
!==
hamburger
){
navbar
.
classList
.
remove
(
'
show-menu
'
);
navItems
.
forEach
(
function
(
item
){
item
.
classList
.
remove
(
'
show
'
);
});
}
e
.
stopPropagation
();
// 阻止事件冒泡到父元素
}
});
});
window
.
addEventListener
(
'
resize
'
,
function
()
{
document
.
addEventListener
(
'
click
'
,
function
(
e
){
if
(
window
.
innerWidth
<=
768
){
var
navbar
=
document
.
getElementById
(
'
my-navbar
'
);
if
(
window
.
innerWidth
>
768
){
var
hamburger
=
document
.
querySelector
(
'
.hamburger
'
);
if
(
!
navbar
.
contains
(
e
.
target
)
&&
e
.
target
!==
hamburger
){
navbar
.
classList
.
remove
(
'
show-menu
'
);
navItems
.
forEach
(
function
(
item
){
item
.
classList
.
remove
(
'
show
'
);
});
}
});
}
});
function
over
(
el
){
if
(
window
.
innerWidth
>
768
){
el
.
children
[
0
].
classList
.
add
(
'
active
'
);
if
(
el
.
children
.
length
>
1
){
let
son
=
el
.
children
[
1
];
son
.
style
.
display
=
"
block
"
;
setTimeout
(
function
(){
son
.
style
.
opacity
=
1
;
},
10
);
}
}
window
.
addEventListener
(
'
resize
'
,
function
()
{
var
navbar
=
document
.
getElementById
(
'
my-navbar
'
);
if
(
window
.
innerWidth
>
768
){
navbar
.
classList
.
remove
(
'
show-menu
'
);
navItems
.
forEach
(
function
(
item
){
item
.
classList
.
remove
(
'
show
'
);
});
}
});
function
leave
(
el
){
if
(
window
.
innerWidth
>
768
){
el
.
children
[
0
].
classList
.
remove
(
'
active
'
);
if
(
el
.
children
.
length
>
1
){
let
son
=
el
.
children
[
1
];
son
.
style
.
opacity
=
0
;
setTimeout
(
function
(){
son
.
style
.
display
=
"
none
"
;
},
300
);
}
}
function
over
(
el
){
if
(
window
.
innerWidth
>
768
){
el
.
children
[
0
].
classList
.
add
(
'
active
'
);
if
(
el
.
children
.
length
>
1
){
let
son
=
el
.
children
[
1
];
son
.
style
.
display
=
"
block
"
;
setTimeout
(
function
(){
son
.
style
.
opacity
=
1
;
},
10
);
}
}
}
navItems
.
forEach
(
function
(
item
){
item
.
addEventListener
(
'
mouseover
'
,
function
(){
over
(
this
);
});
item
.
addEventListener
(
'
mouseleave
'
,
function
(){
leave
(
this
);
});
function
leave
(
el
){
if
(
window
.
innerWidth
>
768
){
el
.
children
[
0
].
classList
.
remove
(
'
active
'
);
if
(
el
.
children
.
length
>
1
){
let
son
=
el
.
children
[
1
];
son
.
style
.
opacity
=
0
;
setTimeout
(
function
(){
son
.
style
.
display
=
"
none
"
;
},
300
);
}
}
}
navItems
.
forEach
(
function
(
item
){
item
.
addEventListener
(
'
mouseover
'
,
function
(){
over
(
this
);
});
item
.
addEventListener
(
'
mouseleave
'
,
function
(){
leave
(
this
);
});
});
// 将toggleMenu函数绑定到汉堡图标
document
.
querySelector
(
'
.hamburger
'
).
addEventListener
(
'
click
'
,
toggleMenu
);
});
</script>
</body>
</html>
\ 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