You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

// 这是自定义JS文件用于覆盖主题默认JS文件
document.addEventListener('DOMContentLoaded', function() {
// 菜单切换
const menuToggle = document.querySelector('.menu-toggle');
const navRight = document.querySelector('.nav-right');
if (menuToggle && navRight) {
menuToggle.addEventListener('click', function() {
navRight.classList.toggle('active');
// 切换菜单按钮动画
const spans = this.getElementsByTagName('span');
this.classList.toggle('active');
if (this.classList.contains('active')) {
spans[0].style.transform = 'rotate(45deg) translate(5px, 5px)';
spans[1].style.opacity = '0';
spans[2].style.transform = 'rotate(-45deg) translate(7px, -7px)';
} else {
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
}
// 滚动时改变导航栏样式
let lastScroll = 0;
const nav = document.querySelector('.main-nav');
window.addEventListener('scroll', function() {
const currentScroll = window.pageYOffset;
if (currentScroll > lastScroll && currentScroll > 80) {
// 向下滚动
nav.style.transform = 'translateY(-100%)';
} else {
// 向上滚动
nav.style.transform = 'translateY(0)';
}
lastScroll = currentScroll;
});
});