Skip to content
Snippets Groups Projects
Commit b83b5498 authored by HouTeng Chan's avatar HouTeng Chan
Browse files

Update file menu.html

parent c1ba6277
No related branches found
No related tags found
No related merge requests found
Pipeline #499326 passed
......@@ -208,31 +208,6 @@
</nav>
<script>
function over(el){
el.children[0].classList.add('active');
if (el.children.length > 1){
let son = el.children[1];
if (getComputedStyle(son,null)["display"]=="none"){
son.style.display = "block";
setTimeout(function(){
son.style.opacity = 1;
}, 10);
}
}
}
function leave(el){
el.children[0].classList.remove('active');
if (el.children.length > 1){
let son = el.children[1];
if (getComputedStyle(son,null)["display"]=="block"){
son.style.opacity = 0;
setTimeout(function(){
son.style.display = "none";
}, 300);
}
}
}
// 修改菜单切换功能
function toggleMenu(){
var navbar = document.getElementById('my-navbar');
navbar.classList.toggle('show-menu');
......@@ -243,12 +218,27 @@
navItems.forEach(function(item){
item.addEventListener('click', function(e){
if(window.innerWidth <= 768){
e.preventDefault();
this.classList.toggle('show');
if(this.querySelector('.son')){
e.preventDefault();
this.classList.toggle('show');
}
}
});
});
document.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');
});
}
}
});
window.addEventListener('resize', function() {
var navbar = document.getElementById('my-navbar');
if(window.innerWidth > 768){
......@@ -258,6 +248,41 @@
});
}
});
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);
}
}
}
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);
});
});
</script>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment