将ngx-scrollbar用于ngx-bootstrap的选项卡选项卡

问题描述 投票:8回答:2

在我的项目中,我使用的是bootstrap 4和ngx-bootstrap。现在我需要创建一个包含2个可滚动div的组件,由制表符切换。

我想在stackblitz中展示一个示例应用程序,但我无法创建它。

所以这是我要放置这些标签的组件:

<div class="d-flex flex-column h-100">
  <div class="border-bottom align-items-center d-flex flex-shrink-0 pr-3 pl-3" style="height: 60px !important;">
    <input type="text" class="form-control" id="search" placeholder="Search...">
  </div>
  <tabset [justified]="true">
    <tab heading="Title 1">
      <ng-scrollbar [autoHide]="true">
        <app-foo-list></app-foo-list>
      </ng-scrollbar>
    </tab>
    <tab class="" heading="Title 2">
      <ng-scrollbar [autoHide]="true">
         <app-foo-list></app-foo-list>
      </ng-scrollbar>
    </tab>
  </tabset>
</div>

在AppFooList组件中,我将放置一个项目列表。例如,它类似于以下代码:

    hiiiiiiii <br>
    hiiiiiiii <br>
    hiiiiiiii <br>
    hiiiiiiii <br>
    ...

你可以帮我修改我的代码,使其正常工作吗? Ngx滚动条不适用于标签的内容。我的所有尝试都以滚动整个应用程序结束,因为内容的高度比应用程序的其余部分高,或者内容可滚动但是ngx滚动条未应用且滚动条很难看。我需要div的高度作为底部空间的其余部分。这就是我使用flexbox的原因。

编辑:code in stackblitz

css angular twitter-bootstrap flexbox ngx-bootstrap
2个回答
2
投票

更新

试试这个

检查演示here

<div class="d-flex flex-column h-100">
  <div class="border-bottom align-items-center d-flex flex-shrink-0 pr-3 pl-3" style="height: 60px !important;">
    <input type="text" class="form-control" id="search" placeholder="Search...">
  </div>
  <tabset [justified]="true">
    <tab heading="Title 1" [ngStyle]="{'height':'calc(100vh - ' + offsetHeightVal + 'px)'}">
      <ng-scrollbar [autoHide]="true">
        <app-foo-list></app-foo-list>
      </ng-scrollbar>
    </tab>
    <tab class="" heading="Title 2" [ngStyle]="{'height':'calc(100vh - ' + offsetHeightVal + 'px)'}">
      <ng-scrollbar [autoHide]="true">
         <app-foo-list></app-foo-list>
      </ng-scrollbar>
    </tab>
  </tabset>
</div>

app.component.ts

import { Component, AfterViewInit } from '@angular/core';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  name = 'Angular 6';
  offsetHeightVal: number; //default value

  offset(el) {
    var rect = el.getBoundingClientRect(),
      scrollLeft = window.pageXOffset || document.documentElement.scrollLeft,
      scrollTop = window.pageYOffset || document.documentElement.scrollTop;
      return { top: rect.top + scrollTop, left: rect.left + scrollLeft }
  }
  ngAfterViewInit() {
    this.offsetHeightVal = this.offset(document.querySelector('.tab-content')).top
  }
}

1
投票

您可以将高度应用于ng-scrollbar

ng-scrollbar {
  height: 80vh;
}

Here is an edit of your stackblitz.

© www.soinside.com 2019 - 2024. All rights reserved.