我试图在视图宽度为 992 像素及以下时单击事件时扩大元素的大小,并希望在视图宽度高于 993 像素时自动删除该元素。请指导我如何去做?
if (sidebarbtn_div.style.display == 'flex') {
const changesidebarbtn = () => {
sidebarbtn.forEach(item => {
item.classList.remove('active')
})
};
sidebarbtn.forEach(disbtn => {
disbtn.addEventListener('click', () => {
changesidebarbtn();
if (disbtn.classList.contains('close_left')) {
document.querySelector('.dis_left').classList.add('active');
document.querySelector('#class_middle').style.width = '96vw';
sidebar.style.display = 'none'
} else if (disbtn.classList.contains('dis_left')) {
document.querySelector('.close_left').classList.add('active');
document.querySelector('#class_middle').style.width = '100%';
sidebar.style.display = 'block'
};
})
})
} else if (sidebarbtn_div.style.display == 'none') {
document.querySelector('#class_middle').style.width = '100%';
sidebar.style.display = 'block'
}
这是事件按钮的 HTML
<div class="sidebar_button d-flex d-lg-none justify-content-center align-items-center z-3">
<span class="close_left active p-2 py-3 rounded-circle" title="Close_left">×</span>
<span class="dis_left p-2 py-3 rounded-circle" title="Dis_left">≻</span>
</div>