响应式菜单切换变为不可见(Responsive Menu toggle goes invisible)

编程入门 行业动态 更新时间:2024-10-28 08:29:00
响应式菜单切换变为不可见(Responsive Menu toggle goes invisible)

我想在切换和事件功能上切换响应式菜单。 菜单无形地滑动到页面底部。

<div class="header"> <span class="navButton"></span> <ul class="nav"> <li><a href="index.html">Home</a></li> <li><a href="journey.html">The Journey</a></li> <li><a href="getintouch.html">Get In Touch</a></li> </ul> </div>

CSS

.nav { position: relative; text-align: center; width: 100%; background-color: black; } .nav>li { display: none; } .navButton{ display: block; background-color: black; color: white; font-size: 40px; text-align: center; cursor: pointer; } .navButton:before { content: "Menu"; }

JavaScript的

$(document).ready(function () { $(".navButton").click(function () { $(".nav").slideToggle(); }); });

I wanted to toggle a responsive menu, upon the toggle and event function. The menu slides invisibly at the bottom of the page.

<div class="header"> <span class="navButton"></span> <ul class="nav"> <li><a href="index.html">Home</a></li> <li><a href="journey.html">The Journey</a></li> <li><a href="getintouch.html">Get In Touch</a></li> </ul> </div>

CSS

.nav { position: relative; text-align: center; width: 100%; background-color: black; } .nav>li { display: none; } .navButton{ display: block; background-color: black; color: white; font-size: 40px; text-align: center; cursor: pointer; } .navButton:before { content: "Menu"; }

JavaScript

$(document).ready(function () { $(".navButton").click(function () { $(".nav").slideToggle(); }); });

最满意答案

在您当前的代码中,您隐藏了所有的li ,因此当您切换ul的display时, li仍然是隐藏的。 删除display:none; 在li并将其添加到ul 。

$(document).ready(function () {      
     $(".navButton").click(function () {          
         $(".nav").slideToggle();          
     });
});   
  
.nav {  
   position: relative;  
   text-align: center;  
   width: 100%;  
   background-color: black;
   display:none;
}
.navButton{  
   display: block;  
   background-color: black;  
   color: white;  
   font-size: 40px;  
   text-align: center;  
   cursor: pointer;  
}  
.navButton:before {  
   content: "Menu";  
} 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="header">
    <span class="navButton"></span>  
    <ul class="nav">  
        <li><a href="index.html">Home</a></li>  
        <li><a href="journey.html">The Journey</a></li>  
        <li><a href="getintouch.html">Get In Touch</a></li>  
    </ul>  
</div> 
  
 

In your current code you are hiding all your lis, so when you toggle the display of the ul, the lis are still hidden. Remove the display:none; on the li and add it to the ul instead.

$(document).ready(function () {      
     $(".navButton").click(function () {          
         $(".nav").slideToggle();          
     });
});   
  
.nav {  
   position: relative;  
   text-align: center;  
   width: 100%;  
   background-color: black;
   display:none;
}
.navButton{  
   display: block;  
   background-color: black;  
   color: white;  
   font-size: 40px;  
   text-align: center;  
   cursor: pointer;  
}  
.navButton:before {  
   content: "Menu";  
} 
  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="header">
    <span class="navButton"></span>  
    <ul class="nav">  
        <li><a href="index.html">Home</a></li>  
        <li><a href="journey.html">The Journey</a></li>  
        <li><a href="getintouch.html">Get In Touch</a></li>  
    </ul>  
</div> 
  
 

更多推荐

本文发布于:2023-07-07 04:20:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:菜单   Responsive   Menu   toggle   invisible

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!