// 动画滚动 document.addEventListener('DOMContentLoaded', function () { const sections = document.querySelectorAll('.introduction'); const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate'); } }); }, { threshold: 0.1 }); sections.forEach(section => { observer.observe(section); }); }); document.addEventListener('DOMContentLoaded', function () { const sections = document.querySelectorAll('.education'); const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate'); } }); }, { threshold: 0.1 }); sections.forEach(section => { observer.observe(section); }); }); document.addEventListener('DOMContentLoaded', function () { const sections = document.querySelectorAll('.skill'); const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate'); } }); }, { threshold: 0.1 }); sections.forEach(section => { observer.observe(section); }); }); document.addEventListener('DOMContentLoaded', function () { const sections = document.querySelectorAll('.project'); const observer = new IntersectionObserver(entries => { entries.forEach(entry => { if (entry.isIntersecting) { entry.target.classList.add('animate'); } }); }, { threshold: 0.1 }); sections.forEach(section => { observer.observe(section); }); }); // 电梯导航 const elevator = document.querySelector('.elevator') window.addEventListener('scroll', function () { const n = document.documentElement.scrollTop // if (n >= 300) { // elevator.style.opacity = 1 // } else { // elevator.style.opacity = 0 // } elevator.style.opacity = n >= 300 ? 1 : 0 }) const backTop = document.querySelector('#backTop') backTop.addEventListener('click', function () { console.log(1) document.documentElement.scrollTop = 0 }) const ul = document.querySelector('.elevator ul') ul.addEventListener('click', function (e) { console.log(1) if (e.target.tagName === 'A') { // 获得自定义属性 // console.log(e.target.dataset.name) // console.log(document.querySelector(`.${e.target.dataset.name}`).offsetTop) const top = document.querySelector(`.${e.target.dataset.name}`).offsetTop document.documentElement.scrollTop = top } })