简体   繁体   English

如何使用 Jquery 或 Javascript 实现展开和关闭 - 滑动菜单?

[英]How to Implement Expand and Close using Jquery or Javascript - sliding menus?

I have a left navigation menu in my page.我的页面中有一个左侧导航菜单。

I need to use something like that navigation window will be closed by default the very first time when the page loads.我需要使用类似导航 window 在页面加载时默认关闭的东西。

If the user wants to view the navigation menu he/she needs to click a small icon above the navigation menu eg: ">>" and click "<<" if they want to close it如果用户想要查看导航菜单,他/她需要点击导航菜单上方的一个小图标,例如:“>>”,如果他们想关闭它,请点击“<<”

Which control do I need to use for this in Jquery.我需要在 Jquery 中为此使用哪个控件。

Thanks谢谢

You can hide anything in jQuery with hide() .您可以使用hide() jQuery 中的任何内容。

So for example, if your menu children have the class .children , you would call this at the beginning of your script:因此,例如,如果您的菜单子项具有 class .children ,您可以在脚本的开头调用它:

$(".children").hide();

when you had a menu like:当你有这样的菜单时:

<div class="menu">
  <div class="parent">Foo 1</div>
    <div class="children">Bar 1</div>
    <div class="children">Bar 2</div>
    <div class="children">Bar 3</div>
  <div class="parent">Foo 2</div>  
    <div class="children">Baz 1</div>
</div>

Let's say you have a >> button which has the ID #expand .假设您有一个 ID #expand>>按钮。 In order to "slide" the children down (to make them visible) you could do:为了“滑动”孩子们(使他们可见),你可以这样做:

$("#expand").click(function(){
  $(".children").slideDown();
});

The same holds for sliding them up to make them invisible again:它们向上滑动以使它们再次不可见也是如此:

$("#collapse").click(function(){
  $(".children").slideUp();
});

Although I don't understand entirely your problem, but you can add a Link like:虽然我不完全理解你的问题,但你可以添加一个链接,如:

<a id="myID" href="#">>></a>

then associate a click event to this link然后将点击事件关联到此链接

$('a#myID').click(function(){
// Show or hide your division for example
});
$('a.click').click(function() {
  var html = $(this).html() == '&raquo;' ? '&laquo;' : '&raquo;';
  $(this).html(html);
  $('div.target').toggle();
});

Try that, replacing the.click and.target class names where appropriate.试试看,在适当的地方替换 .click 和 .target class 名称。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM