【发布时间】:2019-07-28 20:49:00
【问题描述】:
网页:http://www.webbuilders.biz/test-durrani/index.html
Codepen:https://codepen.io/mitchellbarron10/pen/EqZjQj
JavaScript 在 html 代码中。
我需要帮助以在页面加载时关闭导航栏(位于页面右上角)。点击时需要打开,点击X时需要关闭(在导航栏的右上角)
我尝试使用两个不同的按钮,一个用于 openbtn,一个用于 closebtn
<div id="main">
<button class="openbtn" onclick="openNav()">☰</button>
<ul id="menuicons">
<a href="../html-link.htm"><img src="images/noun_Login_801390.png" width="82" height="86" title="White flower" alt="Flower"></a>
<a href="../html-link.htm"><img src="images/noun_Shopping Cart_17861.png" width="82" height="86" title="White flower" alt="Flower"></a>
</ul>
</div>
<script>
script type="text/javascript">/* Set the width of the sidebar to 250px and the left margin of the page content to 250px */
function openNav() {
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
/* Set the width of the sidebar to 0 and the left margin of the page content to 0 */
function closeNav() {
document.getElementById("mySidebar").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
} </script>
<script type="text/javascript">/* Set the width of the sidebar to 250px and the left margin of the page content to 250px */
function openNav() {
document.getElementById("mySidebar").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
}
/* Set the width of the sidebar to 0 and the left margin of the page content to 0 */
function closeNav() {
document.getElementById("mySidebar").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
}</script>
【问题讨论】:
标签: html css button bootstrap-4 toggle