如何使Foundation 5的离屏导航菜单粘性?

7
我正在使用最新版本的Foundation添加一个抽屉式导航菜单,并在选项卡栏中添加切换按钮。虽然我已经使选项卡栏固定,但抽屉式菜单的内容却随着页面滚动。我如何使菜单内容固定,以便在任何大小的屏幕或页面垂直滚动位置上,点击菜单切换将显示菜单内容而无需滚动?到目前为止,我的HTML代码如下:
<!doctype html>
<html class="no-js" lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Foundation | Welcome</title>
    <link rel="stylesheet" href="css/foundation.css" />
    <script src="js/vendor/modernizr.js"></script>
</head>
<body>
    <div class="off-canvas-wrap" data-offcanvas>
        <div class="contain-to-grid sticky">
            <nav class="tab-bar top-bar" data-topbar data-options="sticky_on: large">
                <section class="left-small">
                    <a class="left-off-canvas-toggle menu-icon" href="#"><span></span></a>
                </section>

                <section class="middle tab-bar-section">
                    <h1 class="title">Foundation</h1>
                </section>
            </nav>
        </div>

        <div class="inner-wrap">

            <!-- Off Canvas Menu -->
            <aside class="left-off-canvas-menu">
                <!-- whatever you want goes here -->
                <ul>
                    <li><a href="#">Item 1</a></li>
                    <li><a href="#">Item 2</a></li>
                    <li><a href="#">Item 3</a></li>
                    <li><a href="#">Item 4</a></li>
                    <li><a href="#">Item 5</a></li>
                </ul>
            </aside>

            <div class="row">
                <div class="large-12 columns">
                    <h1>Welcome to Foundation</h1>
                </div>
            </div>

            <!-- Content goes here -->

            <!-- close the off-canvas menu -->
            <a class="exit-off-canvas"></a>

        </div>
    </div>

    <script src="js/vendor/jquery.js"></script>
    <script src="js/foundation.min.js"></script>
    <script>
        $(document).foundation();
    </script>
</body>
</html>

嘿,看看这里的第一篇帖子:http://foundation.zurb.com/forum/posts/547-off-canvas-with-fixed-top-bar?page=2 如果你正在寻找与我相同的效果,它似乎正常工作。 - Tony Barsotti
请记得将您采用的答案标记为已接受。 - tehlivi
3个回答

3

将内容的高度设置为95vh,overflow-y属性设置为scroll。右侧内容滚动时,离屏菜单不受影响,仍保持在顶部。

CSS:

.mycontent {     
  height:95vh;
  overflow-y:scroll;
  /* fix scrolling on webkit touch devices (iPhone etc) */
  -webkit-overflow-scrolling: touch; 
} 

HTML:

  <div class="row mycontent" >
      <div class="large-12 columns">
          <h1>Welcome to Foundation</h1>
      </div>
  </div>

1
这是一个关于vh和vw浏览器支持的好链接:http://caniuse.com/#feat=viewport-units - Lee Duckworth
1
为了澄清,类“mycontent”仅包含页面内容,不包括选项卡栏或画布菜单。这可以在不添加“sticky”或“fixed”类的情况下实现。 - tehlivi
1
这也会影响在iPhone上的平滑滚动,导致滚动不流畅。在Android上则没有问题。 - tehlivi

0

在 CSS 中尝试这个(百分之百有效)

.tab-bar {
  position: fixed;
  width: 100%;
  z-index: 702;
}

问题要求使侧滑部分粘在页面上,但实际只把选项卡栏固定了。 - tehlivi

0

我遇到了同样的问题,无法在打开时保持它。最终我使用了这个:

CSS:

.tab-bar {
position: fixed;
z-index: 9999;
width: 100%;
}

Added an inner wrapper for the off canvas menu right after the "<aside>" tag, before the "off-canvas-list" <ul>s. 
.inner-canvas-menu-wrapper
{ 
position: fixed; 
top: 0; 
overflow-y: hidden; 
width: inherit;
padding-top: 2.8125rem; (standard height of the "tab-bar")
} 

JS

修改了foundation.offcanvas.js的设置选项open_method为"overlap"

现在它是覆盖式的,但至少它是固定的/粘性的。在这个设置中,您可能也想将close_on_click更改为"true"。

如果您使用的是Foundation 6,则默认情况下它将被固定: https://foundation.zurb.com/sites/docs/off-canvas.html#sass-reference


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接