[英]Make sub nav slidedown and slideup toggle
Here's what I'm trying to do: 这是我想做的事情:
Create a navigation with a sub-nav or child page. 使用子导航或子页面创建导航。
When the user clicks on about, I want the about to toggle the Bob li. 当用户单击“关于”时,我希望“关于”切换Bob li。
It should slide down and slide up when clicked on and off of about. 单击大约时,它应该向下滑动并向上滑动。
$(document).ready(function() { $("#grab").click(function() { $(".sub-nav").slideToggle(); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul class="nav"> <li id="#grab">About <ul class="sub-nav"> <li>Bob</li> </ul> </li> <li>Contact</li> <li>Faqs</li> </ul>
Your HTML is wrong you have a hashtag before grab id="#grab"
it should be id="grab"
by default the li contain "Bob" will be show to resolve this issue, add display:none;
您的HTML是错误的,在获取id="#grab"
之前您有一个id="#grab"
标签,默认情况下应为id="grab"
,其中显示出li包含“ Bob”可以解决此问题,请添加display:none;
to the ul either through a class or inline 通过课程或内联向ul致
$(document).ready(function() { $("#grab").click(function() { $(".sub-nav").stop().slideToggle(); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <ul class="nav"> <li id="grab">About <ul style="display:none" class="sub-nav"> <li >Bob</li> </ul> </li> <li>Contact</li> <li>Faqs</li> </ul>
The #
is used to reference id, in your tag you're seting the id as #grab
, and in your jquery you're setting the .click() event to the class grab
. #
用于引用ID,在您的标记中,将ID设置为#grab
,在jquery中,您将#grab
()事件设置为类grab
。 Then you'll need to change your <li>
id to grab
: 然后,您需要更改您的<li>
id以grab
:
<li id="grab">
You can add display: none
to your <ul>
. 您可以将display: none
添加到您的<ul>
。 In that way, when the page load, the sub-nav
starts hidden: 这样,当页面加载时, sub-nav
开始隐藏:
You can set this on the tag: 您可以在标签上进行设置:
<ul class="sub-nav" style="display: none;">
Or in your css: 或在您的CSS中:
.sub-nav{
display: none;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.