gpt4 book ai didi

javascript - 如何修复幻灯片导航

转载 作者:行者123 更新时间:2023-12-01 00:08:39 25 4
gpt4 key购买 nike

我正在研究这个滑动菜单。它可以很好地滑动,但无法通过单击 x 将其关闭。

let openNav = document.querySelector(".slideOpen");
let closeNav = document.querySelector(".slideClose");
document.addEventListener("click", () => {
openNav.style.width = "250px";
});
document.addEventListener("click", () => {
closeNav.style.width = "0";
});
.slideOpen { height: 100%; width: 0; position: fixed; z-index: 1;     top: 0; left: 0; background-color: #111; overflow-x: hidden;   transition: 0.5s; padding-top: 60px; }

.slideOpen a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #818181; display: block; transition: 0.3s; }

.slideOpen a:hover { color: #f1f1f1; }

.slideOpen .slideClose { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; }
<div style="font-size:30px;cursor:pointer">&#9776; open</div> 
<div class="slideOpen"> <ul>
<li> <a href="#" class="slideClose">&times;</a> </li>
<li> <a href="#">About</a> </li>
<li> <a href="#">Services</a> </li>
<li> <a href="#">Clients</a> </li>
<li> <a href="#">Contact</a> </li>
</ul> </div>

最佳答案

您需要在按钮(链接)而不是文档上添加actionListener。

let slide = document.querySelector(".slide");
let slideOpen = document.querySelector(".slideOpen");
let slideClose = document.querySelector(".slideClose");
slideOpen.addEventListener('click', function(event) {
slide.style.width = "250px";
});
slideClose.addEventListener("click", () => {
slide.style.width = "0";
});
.slide { height: 100%; width: 0; position: fixed; z-index: 1;     top: 0; left: 0; background-color: #111; overflow-x: hidden;   transition: 0.5s; padding-top: 60px; }

.slide a { padding: 8px 8px 8px 32px; text-decoration: none; font-size: 25px; color: #818181; display: block; transition: 0.3s; }

.slide a:hover { color: #f1f1f1; }

.slide .slideClose { position: absolute; top: 0; right: 25px; font-size: 36px; margin-left: 50px; }
<div style="font-size:30px;cursor:pointer" class="slideOpen">&#9776; open</div> 
<div class="slide"> <ul>
<li> <a href="#" class="slideClose">&times;</a> </li>
<li> <a href="#">About</a> </li>
<li> <a href="#">Services</a> </li>
<li> <a href="#">Clients</a> </li>
<li> <a href="#">Contact</a> </li>
</ul> </div>

关于javascript - 如何修复幻灯片导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60200382/

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