【问题标题】:How to set start y-position of ion-content scroll?如何设置离子内容滚动的起始 y 位置?
【发布时间】:2019-10-04 19:41:38
【问题描述】:

我正在尝试将ion-content 的滚动位置设置为向下一点以隐藏该控件开头的一些元素。

我需要一些东西like this

我尝试了 'start-y="xx"' 属性,但它不起作用。

有什么建议吗?

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

【问题讨论】:

  • 你在使用 ionic 4 吗?

标签: angular ionic-framework scroll-position ion-content


【解决方案1】:

在 ionic4 中,当前没有滚动起始位置的属性。但是,您可以在页面初始化时使用滚动方法,您可以像这样使用:

.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(()=>{}) }
    }
}

如果您需要任何澄清,请发表评论

【讨论】:

  • 我只是将 'IonContent' 替换为 'Content' 和方法 this.theContent.scrollTo(0,150).then(()=>{}) 它对我有用!谢谢楼主。
猜你喜欢
  • 2015-06-19
  • 2018-02-23
  • 1970-01-01
  • 2013-05-02
  • 1970-01-01
  • 1970-01-01
  • 2019-09-22
  • 2019-10-15
  • 1970-01-01
相关资源
最近更新 更多