点击外面的Boostrap Offcanvas边栏菜单吧?

时间:2015-10-01 09:34:13

标签: css menu

*你好,朋友们!

我试图为我的网站修改Boostrap Offcanvas模板。

工作示例如下:

http://getbootstrap.com/examples/offcanvas/

它对我来说非常完美,我唯一想补充的是通过点击/点击它来关闭侧边栏菜单(现在它只能通过点击切换按钮来工作)。

如果我理解正确,CSS中的几行可以提供帮助。我的想法是:(可能)添加一些div ,其中包含主要内容,并且 data-toggle =" offcanvas"侧边栏菜单处于活动状态时,data-target ="#sidebar"

感谢您的帮助,因为我无法找到解决方案。

HTML

<div class="container">
      <div class="row row-offcanvas row-offcanvas-right">
        <div class="col-xs-12 col-sm-9">
          <p class="pull-right visible-xs">
            <button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas">Toggle nav</button>
          </p>
          <div class="row">
            <div class="col-xs-6 col-lg-4">
              <h2>Heading</h2>
              <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
              <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
            </div><!--/.col-xs-6.col-lg-4-->
            <div class="col-xs-6 col-lg-4">
              <h2>Heading</h2>
              <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
              <p><a class="btn btn-default" href="#" role="button">View details &raquo;</a></p>
            </div><!--/.col-xs-6.col-lg-4-->
                      </div><!--/row-->
        </div><!--/.col-xs-12.col-sm-9-->

        <div class="col-xs-6 col-sm-3 sidebar-offcanvas" id="sidebar">
          <div class="list-group">
            <a href="#" class="list-group-item active">Link</a>
            <a href="#" class="list-group-item">Link</a>
            <a href="#" class="list-group-item">Link</a>

          </div>
        </div><!--/.sidebar-offcanvas-->
      </div><!--/row-->

CSS:

@media screen and (max-width: 767px) {
  .row-offcanvas {
  position: relative;
  -webkit-transition: all .25s ease-out;
  -o-transition: all .25s ease-out;
  transition: all .25s ease-out;
  }

  .row-offcanvas-right {
right: 0;
  }


  .row-offcanvas-right
  .sidebar-offcanvas {
    right: -50%; /* 6 columns */
  }


  .row-offcanvas-right.active {
    right: 50%; /* 6 columns */
  }

  .sidebar-offcanvas {
    position: absolute;
    top: 0;
    width: 50%; /* 6 columns */
  }
}

JS

$(document).ready(function () {
  $('[data-toggle="offcanvas"]').click(function () {
    $('.row-offcanvas').toggleClass('active')
  });
});

0 个答案:

没有答案