所以我有這個關閉畫布菜單,幾乎可以工作,但不是很完美! 菜單從右側推入,但網站的其餘部分未被推到左側。我很確定我錯過了CSS中的某些東西,即我正在切換的類(.toggleNav)! 雖然不知道,需要你的幫助!非常感謝!!關閉畫布菜單不會將內容推開
$(document).ready(function(e) {
\t
\t $('#toggleMenu').click(function() {
\t $('#siteWrapper').toggleClass('toggleNav');
\t });
\t
});
* {padding:0;margin:0;font-family:Helvetica,sans-serif;font-weight:normal}
body, html {width: 100%;height: 100%;}
ul {list-style:none;padding-left:10px;}
#siteWrapper{
\t overflow:hidden;
\t position:relative;
\t width: 100%;
\t height: 40%;
\t background: lightgrey; \t
}
#canvasWrapper {
\t position:absolute;
\t top: 0;
\t right:-400px;
\t width: 400px;
\t height: 100%;
\t background: #3186CD; \t
}
#siteWrapper, #canvasWrapper {
\t -webkit-transform: translateX(0);
\t transform: translateX(0);
\t -webkit-transition: \t .3s ease all;
\t transition: .3s ease all;
}
#siteWrapper.toggleNav #canvasWrapper { /* quite possibly wrong... */
\t -webkit-transform: translateX(-400px);
\t transform: translateX(-400px); \t
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div id="siteWrapper">
<h1>Off Canvas Menu</h1><br>
<h3>This should slide to the left! Some more text to have something left on the canvas...</h3><br>
\t <div id="canvasWrapper" >
\t <div id="menu">
\t <ul>
\t <li>home</li>
<li>infos</li>
<li>something</li>
<li>contact</li>
</ul>
</div>
</div>
</div>
<a href="#" id="toggleMenu">toggle Menu</a>
感謝您的反饋,我已經嘗試過這一點,它使菜單向左移動800px而不是400px ...我假設它的總和爲400px fr om #sitewrapper加上#canvasWrapper的400px? – Ollie
好了,然後將css僅應用於.toggleNav,所以如果它向左移動400px,則會顯示offcanvas。 – Ahmadbaba46
現在只有灰色的畫布移動到左側,但是畫布外的菜單不會移入... – Ollie