简体   繁体   English

如果超出浏览器边缘,则在左侧显示引导菜单或子菜单

[英]make bootstrap menu or sub-menu visible in left side if it's going beyond browser edge

Check my FIDDLE , as you can see there are some dropdown menus,please resize the browser in a way that 'Dropdown' menu will come to right side. 检查我的FIDDLE ,因为您可以看到有一些下拉菜单,请以“下拉菜单”右侧的方式调整浏览器的大小。 Then go to '2nd level menu' as you can see submenu are opening in right side, hence they are not visible fully. 然后转到“第二级菜单”,因为您可以看到子菜单在右侧打开,因此它们不能完全显示。 Although we have space in left-side, is there any way we can make sub-menu visible on left if it's going beyond screen. 虽然我们在左侧有空间,但如果它超出屏幕,我们可以在左边看到子菜单。

How it's looking: 看起来如何: 图片

So this is what I want to achieve: 所以这就是我想要实现的目标:

  1. How to detect particular menus is going outside the browser edge?? 如何检测特定菜单是否超出浏览器边缘?
  2. After detection How to make it reverse aligned, so that user can see it. 检测后如何使其反向对齐,以便用户可以看到它。

How it should behave, if there is not enough space in right-side to open submenu, menus will be shown in left-side: 它应该如何表现,如果右侧没有足够的空间打开子菜单,菜单将显示在左侧:

表现出色的行为

HTML HTML

<ul class="nav nav-pills">
  <li class="active"><a href="#">Regular link</a></li>
    <li class="dropdown">
    <a href="#">Menu</a>
  </li>
  <li class="dropdown">
    <a href="#">Menu</a>
  </li>
  <li class="dropdown">
    <a href="#">Menu</a>
  </li>
  <li class="dropdown">
    <a href="#" data-toggle="dropdown" class="dropdown-toggle">Dropdown <b class="caret">        </b></a>
    <ul class="dropdown-menu" id="menu1">
      <li>
      <a href="#">2-level Menu <i class="icon-arrow-right"></i></a>
      <ul class="dropdown-menu sub-menu">
        <li><a href="#">I can be in left side</a></li>
        <li><a href="#">Why i am coming on right side</a></li>
        <li><a href="#">I want to come in Left side</a></li>
        <li><a href="#">Enough space in left</a></li>
        <li><a href="#">I will not be visible as i am long</a></li>
      </ul>
      </li>
      <li><a href="#">Another action</a></li>
      <li><a href="#">Something else here</a></li>
      <li class="divider"></li>
      <li><a href="#">Separated link</a></li>
    </ul>
  </li>
</ul>

你可以用pull-left ,如果在页面右侧的下拉: 小提琴 ,你可以使用一些JS,使其动态浏览器的重新大小,通过计算DIV位置

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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