如何在angular4中滚动元素?

时间:2017-08-07 15:11:19

标签: angular scroll

我很难找到使用滚动动画的角度示例。我使用角度4,我尝试滚动元素。

元素模板:

// Valuable part of component template
<ol #indicatorsList class="carousel-indicators" *ngIf="slides.length > 1">
<li *ngFor="let slide of slides; let i = index;" (click)="selectSlide(i)"
    [class.active]="slide.active === true">
// some content inside
</li>

组件类看起来像这样:

export class NewsCarouselComponent { 

    @ViewChild('indicatorsList')
    indicatorsList: ElementRef; 

    protected _slides: LinkedList<NewsSlideComponent> = new LinkedList<NewsSlideComponent>(); 

    public get slides(): NewsSlideComponent[] {
         return this._slides.toArray();
    }

    public selectSlide(index: number): void {
        this.activeSlide = index;
        let indicatorsHeight = this.indicatorsList.nativeElement.offsetHeight;
        let indicatorsCount = this.indicatorsList.nativeElement.childElementCount;
        let scrollTo = indicatorsHeight / indicatorsCount * index;
        // how to scroll element to position calculated as scrollTo?
      }
}

我想在不使用jQuery的情况下这样做。

0 个答案:

没有答案