我在 html 標記中添加了一個“固定”類,但僅在我網站上的某些頁面上(我想添加位置:固定以阻止滾動)。當我打開漢堡選單時,我希望洗掉該類,以便用戶可以滾動導航。我是這樣做的:
elmHamburger.addEventListener('click', () => {
if (overlay.isOpened === true) {
elmHamburger.classList.add('is-opened-navi', 'is-active');
if ($('html').hasClass('fixed')) {
$('html').removeClass('fixed');
}
} else {
elmHamburger.classList.remove('is-opened-navi', 'is-active');
// how to add it back here?
}
});
當我關閉漢堡選單時,我想將類添加回來,但只添加到以前有它的頁面,而不是所有頁面。怎么做?
uj5u.com熱心網友回復:
也許是這樣的:
elmHamburger.addEventListener('click', () => {
if (overlay.isOpened === true) {
elmHamburger.classList.add('is-opened-navi', 'is-active');
if ($('html').hasClass('fixed')) {
$('html').removeClass('fixed');
$('html').addClass('tmp-fixed');//添加臨時類
}
} 別的 {
elmHamburger.classList.remove('is-opened-navi', 'is-active');
if ($('html').hasClass('tmp-fixed')) {
$('html').addClass('fixed');
$('html').removeClass('tmp-fixed');
}
}
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/504998.html
標籤:javascript jQuery
