如何创建推/滑动菜单

How to create a Push/slide Menu

本文关键字:菜单 何创建 创建      更新时间:2023-09-26

我想在我的网站上创建一个Push/slide out菜单系统,就像www.squarespace.com一样,但是我不知道怎么做。

我的网站是一个Squarespace网站,它使用html, json和更少(你也可以添加。js文件):splitblog.squarespace.com/

我的网站。导航区域文件为:

<squarespace:navigation navigationId="mainNav" template="navigation" />

从导航中提取信息。块,它是:

<nav id="main-navigation" class="main-navigation" data-content-field="navigation-mainNav">
  <ul>
    {.repeated section items}
        <li class="{.section active} active-link{.end}{.if folderActive} active-folder{.end}">
          {.folder?}
            <!--FOLDER-->
              <a href="{collection.fullUrl}">{collection.navigationTitle}</a>
              <ul>
                {.repeated section items}
                  <!--COLLECTION IN A FOLDER-->
                  {.collection?}
                    <li class="{.section active} active-link{.end}">
                      <a href="{collection.fullUrl}">
                        {collection.navigationTitle}
                      </a>
                    </li>
                  {.end}
                  <!--EXTERNAL LINK IN A FOLDER-->
                  {.section externalLink}
                    <li>
                      <a href="{url}"{.section newWindow} target="_blank"{.end}>
                        {title}
                      </a>
                    </li>
                  {.end}
                {.end}
              </ul>
          {.or}
            <!--COLLECTION-->
            {.section collection}
              <a href="{fullUrl}">{navigationTitle}</a>
            {.end}
            <!--EXTERNAL LINK-->
            {.section externalLink}
              <a href="{url}"{.section newWindow} target="_blank"{.end}>
                {title}
              </a>
            {.end}
          {.end}
        </li>
    {.end}
  </ul>
</nav>
菜单的.less样式是:
.main-navigation {
  ul {  
    padding-left: 0;
    li {
      display: inline-block;
      ul {
        display: none;
      }
      &:not(:last-child) {
        margin-right: .5em;
      }
      &:hover > ul {
        display: inline-block;
      }
      &.active-link > a {
        color: salmon;
      }
      &.active-folder > a {
        color: orange;
      }
    }
  }
}

任何帮助都会很感激。请随意提供css和js解决方案。谢谢!

编辑

下面是我想实现的一个例子:codepen

检查这个提琴。

这应该给你一个关于如何实现需求的想法。

$(document).on("click","#button", function(){
    $('#div2').animate({ width:"20%" }, 200);
    $('#div1').animate({width:"80%" }, 200);
});
$(document).on("click","#close", function(){
    $('#div2').animate({visibility:"hidden" , width:"0%" }, 200); 
    $('#div1').animate({width:"100%" }, 200);
});

#div1
{
    height:100%;
    width:100%;
    float:left;
    position:fixed;
}
#div2
{
    height:100%;
    width:0%;
    float:right;
}
#button
{
    margin-top:20px;
    margin-right:20px;
    float:right;
}

这可能会给您一个如何实现这一点的想法。

http://thecodeplayer.com/walkthrough/off-canvas-menu-animated-links

foundation在他们的框架中也有一个offcanvas菜单,你可以看看他们是如何创建的。

http://foundation.zurb.com/docs/components/offcanvas.html