简体   繁体   中英

Foundation - Off Canvas Scroll Issue

I'm starting with Foundation and trying to get an off canvas example working. I've been struggling because the menu opens and closes like it should, however if the page content is long and you scroll toward the bottom, when you open the menu, the focus is where you are on the page. IE, the fixed toolbar and menu aren't fixed when open.

I've done an example on a fiddle, and would love some help!

JSFiddle Example

HTML

<div class="off-canvas-wrap" data-offcanvas="">
  <div class="inner-wrap">
<div class="fixed">
<nav class="tab-bar">
  <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">Forest School - PARS Insight</h1>
  </section>
</nav>
  </div>

<aside class="left-off-canvas-menu">
  <ul class="off-canvas-list">
    <li><label>General</label></li>
    <li><a href="#">Snapshot</a></li>
    <li><a href="#">Timetable</a></li>
    <li><a href="#">Homework</a></li>
  </ul>
</aside>
 Long Body Content Here

CSS

.off-canvas-wrap, .inner-wrap {
    min-height: 100%;
}

.off-canvas-wrap{  
    height: 100%;
    overflow-y: auto;
}

Javascript

$(document).foundation();

This is very popular Foundation issue:

http://foundation.zurb.com/forum/posts/965-fixed-menu-using-offcanvas
http://foundation.zurb.com/forum/posts/547-off-canvas-with-fixed-top-bar
https://github.com/zurb/foundation/issues/3863
https://github.com/zurb/foundation/issues/3710

Despite of it seems that official solution doesn's exist yet I have found this one ( reference ) which looks like a nice fix of your problem.

HTML

<div class="off-canvas-wrap">
   <div class="inner-wrap">
      <div class="header">
         <nav class="tab-bar" data-offcanvas>
            <section class="left-small">
               <a class="left-off-canvas-toggle menu-icon">
                  <span></span>
               </a>
            </section>
            <section class="right tab-bar-section">
               <h1>Foundation 5 test</h1>
            </section>
         </nav>
      </div>
      <aside class="left-off-canvas-menu">
         <ul class="off-canvas-list">
            <li>
               <label>Foundation</label>
            </li>
            [...]
            <li><a href="#">The Psychohistorians</a>
            [...]
            </li>
         </ul>
      </aside>
      <article class="small-12 columns">
         <p>Content</p>
         <p>Content</p>
         <div data-magellan-expedition="fixed">
            <dl class="sub-nav panel">
               <dd data-magellan-arrival="build">
                  <a href="#build">Build with HTML</a>
               </dd>
               <dd data-magellan-arrival="js">
                  <a href="#js">Arrival 2</a>
               </dd>
            </dl>
         </div>
         [...]
         <p>Content</p>
         [...]
      </article>
      <a class="exit-off-canvas"></a>
      <footer class="small-12 columns">
         <div>...</div>
      </footer>
   </div>
</div>

CSS

article {
    overflow-y: auto;
}
article,
body,
html,
.off-canvas-wrap, 
.off-canvas-wrap .inner-wrap,
.row {
    height: 100%;
    width: 100%;
}
.header {
    position: absolute;
    top: 0;
    width: 100%;
    z-index: 99;
}

I dont have enough reputation to comment..so ill add on as an answer to Akarienta's.

I had scrolling problem on mobile browsers with the solution above. I added -webkit-overflow-scrolling: touch for the scrolling to work

article,
.off-canvas-wrap, 
.off-canvas-wrap .inner-wrap
  height: 100%
  width: 100%
  -webkit-overflow-scrolling: touch
article
  overflow-y: auto

thanks to this question

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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