gpt4 book ai didi

html - 首次加载 html 页面时默认打开导航栏

转载 作者:行者123 更新时间:2023-11-28 02:11:45 25 4
gpt4 key购买 nike

如何修改此代码以在页面首次加载时保持侧边导航栏打开?我希望我的侧边导航栏默认打开。

function openNav() {
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
}

function closeNav() {
document.getElementById("mySidenav").style.width = "0";
document.getElementById("main").style.marginLeft = "0";
document.body.style.backgroundColor = "white";
}
<div id="wrapper">
<header>
<div></div>
</header>
<nav>
<span style="font-size:30px;cursor:pointer" onclick="openNav()">&#9776; Learn Here</span>

<div id="mySidenav" class="sidenav">
<img src="https://cloud.netlifyusercontent.com/assets/344dbf88-fdf9-42bb-adb4-46f01eedd629/68dd54ca-60cf-4ef7-898b-26d7cbe48ec7/10-dithering-opt.jpg" height="20%" width="70%" style="padding-left: 36px; padding-right: 36px">
<a href="javascript:void(0)" class="closebtn" onclick="closeNav()">&times;</a>
<a class="nav_padding" href="#">About me</a>
<a class="nav_padding" href="#">Resume</a>
<a class="nav_padding" href="#">Projects</a>
<a class="nav_padding" href="#">Contact Me</a>
<script>
</script>
</div>
</nav>
</div>

最佳答案

在 $(document).ready(function(){ }) 上添加脚本;ready 函数在页面加载时执行 java 脚本,

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<script>
$(document).ready(function(){
document.getElementById("mySidenav").style.width = "250px";
document.getElementById("main").style.marginLeft = "250px";
document.body.style.backgroundColor = "rgba(0,0,0,0.4)";
});
</script>

关于html - 首次加载 html 页面时默认打开导航栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48711192/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com