angularionic-frameworkscroll-positionion-content

How to set start y-position of ion-content scroll?


I'm trying to set up the scroll position of ion-content a little bit down to hide some elements at the beginning of this control.

I need something like this

I have tried 'start-y="xx"' attribute but it doesn't work.

Any suggestions?

<ion-content start-y="55">

Solution

  • In ionic4 there currently isn't an attribute for scroll starting position. However, there is a scroll method you can use on page initialisation which you can use like so:

    .ts

        import { Component, ViewChild } from '@angular/core';
        import {IonContent} from '@ionic/angular';
        @Component({
          selector: 'app-home',
          templateUrl: 'home.page.html',
          styleUrls: ['home.page.scss'],
        })
        export class HomePage {
             @ViewChild(IonContent) theContent: IonContent;
    
    
        ngOnInit() {this.theContent.scrollToPoint(0,150).then(()=>{}) }
        }
    }
    

    comment if you need anything clarifying