最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Foundation - Off Canvas Scroll Issue - Stack Overflow

programmeradmin2浏览0评论

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();

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();
Share Improve this question edited Jan 26, 2015 at 12:55 Knut Holm 4,1624 gold badges35 silver badges55 bronze badges asked Jan 23, 2015 at 15:12 CaseyCasey 1841 gold badge3 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

This is very popular Foundation issue:

http://foundation.zurb./forum/posts/965-fixed-menu-using-offcanvas
http://foundation.zurb./forum/posts/547-off-canvas-with-fixed-top-bar
https://github./zurb/foundation/issues/3863
https://github./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 ment..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

发布评论

评论列表(0)

  1. 暂无评论