我的jQuery侧边栏菜单显示在侧边栏隐藏后点击有问题,叠加层(.backdrop)不会隐藏。
以下是fiddle
HTML
<li class="topHeaderMenu leftMenu listMenu" id="open"><div class="listMenuDiv"><i class="glyphicon glyphicon-align-justify"></i></div></li>
<div class="backdrop"></div>
<div class="sidebar">
content
</div>
的jQuery
$('#open').click(function()
{
$(this).find('i').toggleClass('glyphicon-align-justify').toggleClass('glyphicon-remove');
$('.sidebar').toggleClass('active');
$(".backdrop").toggle();
})
$(document).click(function(e)
{
var sidebar = $(".sidebar, #open");
if(!sidebar.is(e.target) && sidebar.has(e.target).length === 0)
{
$('#open').find('i').toggleClass('glyphicon-align-justify').toggleClass('glyphicon-remove');
sidebar.removeClass('active');
}
});
CSS
p {
text-align: center;
}
ul
{
list-style: none;
}
.sidebar
{
position: fixed;
transform: translateX(-120%);
display: inline-block;
height: 100vh;
background: lightblue;
transition: all 0.3s ease-in;
width: 200px;
z-index: 8;
}
.active
{
transform: translateX(0);
}
.backdrop
{
height: 100vh;
width: 100%;
z-index: 7;
position: fixed;
top: 0;
left: 0;
display: none;
background-color: #000;
opacity: 0.2;
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
-o-transition: all 0.5s ease;
transition: all 0.5s ease;
}
所以问题是,在侧边栏隐藏后,.backdrop不会隐藏。我想要的是在侧栏外单击时隐藏。
答案 0 :(得分:0)
您要删除“有效”课程但不隐藏您的背景div。请使用以下代码
for (size_t i = 0; i < sizeof(some_variable) / sizeof(some_variable[0]); i++) {
// ...
}