7

Perfect Scrollbarを使用してから Angular 2 を使用し始めましたが、同様の追加が見つかりません。Angular 2プロジェクトで完璧なスクロールバーを実装する正しい方法は何ですか?

私はこの素晴らしい例に従いましたが、どのように変更するか迷っていますngOnInit()

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

これに=>

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

2 に答える 2

6

次のように、バニラ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

于 2016-04-29T16:30:06.990 に答える