简体   繁体   English

引导模态中的水平滚动

[英]horizontal scroll in bootstrap modal

Hi i am trying add a horizontal scroll bar in bootstrap modal. 嗨,我正在尝试在bootstrap模式中添加一个水平滚动条。 I know horizontal scroll bars are not a good idea but in my case i have dynamic content which can have variable width so i want to make modal body scroll-able horizontally when width exceed modal body's width. 我知道水平滚动条不是一个好主意,但在我的情况下,我有动态内容,可以有可变宽度,所以我想让模态体水平滚动宽度超过模态体宽度。

here is what i have tried 这是我尝试过的

<div class="modal-header">
<h3 class="modal-title">Decomposition</h3>

  <div class="modal-body">
  <div class="scoll-tree">
       <div class="list-group" ng-repeat="item in items"> 
          <a class="list-group-item" href="javascript:void(0);" ng-click="getChildren(item)">{{item.value}}</a>
       </div>

  </div>

</div>

CSS: CSS:

.modal-body {
     max-width: 900px;
     overflow-x: auto;
}

here is the fiddle what i have tried.. https://jsfiddle.net/4duq2svh/2/ 这是我尝试过的小提琴.. https://jsfiddle.net/4duq2svh/2/

Any help is appreciated. 任何帮助表示赞赏。

Thanks in advance. 提前致谢。

check https://jsfiddle.net/4duq2svh/3/ 检查https://jsfiddle.net/4duq2svh/3/

HTML HTML

<div class="modal-body">
    <div class="scoll-tree">
        <div class="list-group" ng-repeat="item in items"> 
            <a class="list-group-item" href="javascript:void(0);" ng-click="getChildren(item)">{{item.value}}</a>
        </div>
    </div>
</div>

CSS CSS

.modal-body {
    max-width: 100%;
    overflow-x: auto;
}
.scoll-tree {
    width:5000px;
}

JS JS

var totalwidth = 190 * $('.list-group').length;

$('.scoll-tree').css('width', totalwidth);

Here I am calculating .scoll-tree width using jQuery to help horizontal scroll bar appear. 在这里,我使用jQuery计算.scoll-tree宽度,以帮助出现水平滚动条。

Sorry to answer my own question, I solved it by calculating the width of scroll-tree div based on number of list-groups inside, as one single list group is 180px wide the width will be 180 * numberOfItems. 很抱歉回答我自己的问题,我通过根据里面列表组的数量计算滚动树div的宽度来解决它,因为一个单个列表组是180px宽,宽度将是180 * numberOfItems。 here is the code: 这是代码:

$scope.getStyle = function(){
    var numberOfItems = $scope.tree.length;

    return {
        width  : 200 * numberOfItems + 'px',
        overflowX: 'auto'
    }   
}

<div class="modal-body" style="overflow-x: auto;">>
   <div class="scoll-tree" ng-style="getStyle();">
      <div class="list-group" ng-repeat="item in items"> 
        <a class="list-group-item" href="javascript:void(0);" ng-click="getChildren(item)">{{item.value}}</a>
      </div>
   </div>
</div>

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

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