통합검색

Javascript

[Javascript] header 상단에서만 특정 class 추가

  • 2022.07.07 08:58:18
[!]jquery[/!]
// header bg
const headBg = {
    init() {
        this.action();
    },
    action() {
        const $hd = document.querySelector('#header');
        if (!$hd) return;
        ['scroll', 'resize', 'load'].forEach(event => {
            window.addEventListener(event, () => {
                let wt = window.scrollY;
                let hh = $hd.offsetHeight;
                wt > hh ? $hd.classList.add('fix') : $hd.classList.remove('fix');
            });
        });
    }
};
document.addEventListener('DOMContentLoaded', () => {
    headBg.init();
});



- 에이원플러스