Angular2 可滚动内容

Angular2 scrollable content

我用了Perfect Scrollbar,然后开始用Angular2,但是找不到类似的加法。在 Angular 2 项目中实现完美滚动条的正确方法是什么?

我关注了this great example但是我有点迷茫如何在ngOnInit()

中改变
jQuery(this.elementRef.nativeElement).draggable({containment:'#draggable-parent'}); 

对此=>

$(function() {
  $('#Demo').perfectScrollbar();

您可以使用 vanilla js(因为它支持 ;-))在自定义指令中初始化完美滚动条,如下所示:

import Ps from 'perfect-scrollable';

@Directive({
  selector: '[ps]'
})
export class PsDirective {
  constructor(private elementRef:ElementRef) {
  }

  ngAfterViewInit() {
    Ps.initialize(this.elementRef.nativeElement);
  }
}

您可以像这样使用/应用它:

@Component({
  selector: 'app'
  template: `
    <div ps class="container">
      <div class="content"></div>
    </div>
  `,
  styles: [`
    .content {
      background-image: url('https://noraesae.github.io/perfect-scrollbar/azusa.jpg');
      width: 1280px;
      height: 720px;
    }

    .container {
      position: relative;
      margin: 0px auto;
      padding: 0px;
      width: 600px;
      height: 400px;
    }
  `],
  directives: [ PsDirective ]
})
export class App {
}

必须在此之前配置库(css 和 SystemJS):

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/jquery.perfect-scrollbar/0.6.11/css/perfect-scrollbar.min.css"/>

<script>
  System.config({
    transpiler: 'typescript', 
    typescriptOptions: { emitDecoratorMetadata: true }, 
    map: {
      'perfect-scrollable': 'https://cdnjs.cloudflare.com/ajax/libs/jquery.perfect-scrollbar/0.6.11/js/min/perfect-scrollbar.min.js'
    },
    packages: {
      'app': {
        defaultExtension: 'ts'
      }
    } 
  });
  System.import('app/main')
        .then(null, console.error.bind(console));
</script>

看到这个 plunkr:https://plnkr.co/edit/S8DJpHFVNFioklTl1xg6?p=preview

Angular2-drag-scroll 是您正在寻找的图书馆

用法示例:

<style>
  .demo-one {
    height: 260px;
    background-color: #FFFFFF;
  }
</style>

<div drag-scroll drag-scroll-y-disabled="true" scrollbar-hidden="true" >
  <img *ngFor="let image of imagelist" [src]="'assets/img/' + image" />
</div>

我正在将 "drag-scroll" 应用到 div 所以这个 div 的所有内容都将是 可拖动且具有溢出属性:滚动等

将 "drag-scroll-y-disabled" 设置为 true 将禁用 y-axis scrolling/dragging。

将 "scrollbar-hidden" 设置为 true 将隐藏滚动条。

Github 页数:https://github.com/bfwg/angular2-drag-scroll

演示站点:https://bfwg.github.io/angular2-drag-scroll/