How can I use content.scrollTo() for ion-scroll in ionic2?

后端 未结 5 2086
日久生厌
日久生厌 2020-12-05 14:50

I try to scroll to a fixed position, for example scrollTo(500, 20). Let\'s say that you are on a device, which has got a width of 300 pixel. The scroll target is now out of

5条回答
  •  我在风中等你
    2020-12-05 15:56

    To add to the answers above, this will handle smooth scrolling.

    Name the scroll element in your .html

    
    

    Import the scroll.

    import { Scroll } from 'ionic-angular';
    

    Reference the scroller in the .ts

    @ViewChild('scroll') scroll: any;
    

    Add this code where its needed:

    this.scroll._scrollContent.nativeElement.scrollTo({ left: 0, top: 0, behavior: 'smooth' });
    

    Hope that helps somebody.

提交回复
热议问题