準備考試,直接來,不廢話。
const nav = document.querySelector('#main')
const TopofNav = nav.offsetTop
function fixNav(){
if (window.scrollY >= TopofNav) {
document.body.style.paddingTop = nav.offsetHeight + 'px'
document.body.classList.add('fixed-nav')
}else {
document.body.style.paddingTop = 0
document.body.classList.remove('fixed-nav')
}
}
window.addEventListener('scroll', fixNav)
capture:true
top-down 上到下 預設為falsee.stopPropagation()
stop bubbling upconst divs = document.querySelectorAll('div')
function logText(e) {
//e.stopPropagation()
console.log(this.classList.value);
}
divs.forEach(div => div.addEventListener('click', logText, {
capture: false,
once: true
}))