0
我想做一個擴展的側邊欄,我能夠使側邊欄擴展,但是我需要覆蓋按下的原始按鈕。如何在兩個不同的ID /類中使用相同的切換註釋
我想在側面有一個區域,我可以點擊關閉邊欄。
我快到了。我遇到的問題是點擊時關閉ID似乎沒有觸發切換。
這裏是我的代碼
$("#icon-menu-mobile,#exit").each(function() {
$(this).click(function() {
var effect = 'slide';
var options = 'left';
var duration = 500;
$('#panel').toggle(effect, options, duration);
});
});
#panel {
position: absolute;
top: 0px;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
display: none;
z-index: 999;
}
.panelcontent {
position: relative;
top: 50px;
width: 70%;
height: 100%;
background-color: #cccccc;
float: left;
}
#icon-menu-mobile {
width: 36px;
height: 30px;
cursor: pointer;
font-size: 24px;
}
#icon-menu-mobile,
#exit {
position: static;
float: right;
width: 30%;
height: 100%;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<body>
<span id="icon-menu-mobile">
\t ☰ \t \t \t \t \t \t
</span>
<div id="panel">
<div class="panelcontent">
Some text here to fill it out
</div>
<div id="exit">
Click here to exit
</div>
</div>
</body>
正如你可以看到單擊菜單漢堡後,你不能一邊關閉按鈕關閉它。
我在猜測,切換隻能從點擊的第一個ID開始工作,並且需要再次點擊該ID再次切換。
有沒有辦法讓兩個ID激活相同的切換?
我想我是這樣做的。是這個嗎? 很奇怪,演示效果很好,但在我的網站上它只能打開。關閉不起作用... – MKBeans
嘗試' ' – Pabs123
繁榮工程。謝謝。 – MKBeans