【问题标题】:IONIC Scroll to divIONIC 滚动到 div
【发布时间】:2017-08-14 11:37:05
【问题描述】:

IONIC 新手。

所以我显示了很多日期,但是当页面显示时我想滚动到今天。

现在确定我该怎么做? 我确实在模型上有一个标志,告诉它是否是今天,如果这有帮助吗? (即 day.IsToday)

<ion-item-group *ngFor="let day of allAppDays; let i = index;" >


<ion-item-divider color="light"> {{day.Date | date : ' EEE d MMM yyyy' }}</ion-item-divider>

      <button class="appbutton" ion-item *ngFor="let a of day.Appointments" (click)="goToApp(a)">
      <ion-grid>
        <ion-row>
          <ion-col col-3 [class]="getAppClass(a)">
            <p style="padding-top:6px;">{{a.Start|date:'h:mm a'}} <br />{{a.End|date:'h:mm a'}}</p>
            <div class="vertline"></div>
          </ion-col>

          <ion-col>
            <p class="font-sub pl10">{{a.ClientFirstName}} {{a.ClientLastName}}</p>
          </ion-col>
        </ion-row>
      </ion-grid>
      </button>

    </ion-item-group>

//打字稿

    ngOnInit() {

        this.getData();
      }

      //Lets go and get data from the API
      getData() {

        this.getApps(false, () => {
          this.loader.dismiss();
        });
      }
getApps(cacheOnly = false, complete: any = null) {
    this.apiService.getschedule(cacheOnly).subscribe((a: AppointmentDay[]) => {
      this.allAppDays = a;
      if (complete != null) { complete(); }
    }, (err: any) => {
      if (complete != null) { complete(); }
    });
  }

提前谢谢你。

【问题讨论】:

    标签: angular typescript ionic-framework ionic2


    【解决方案1】:

    给你。我剪切并粘贴了旧应用的相关部分。

    您必须进行计算才能设置this.content.scrollTop

    import { Component,ViewChild, Input, Output, EventEmitter} from '@angular/core';
    import {  Content } from 'ionic-angular';
    @Component({
      selector: 'my-page',
      templateUrl: 'myPage.html'
    })
    export class MyPage {    
        @ViewChild(Content)
        content:Content;
    
        @Input("scrolling")
        isScrolling: boolean;
    
        @Output("scrolling")
        scrollingOutput = new EventEmitter();
    
       ionViewDidLoad() :void {
         this.content.ionScroll.subscribe( (event) => {
           this.isScrolling = true;
           this.scrollingOutput.emit(true);
           let scrollTop = this.content.scrollTop
         });
         this.content.ionScrollEnd.subscribe( (event) => {
          this.isScrolling = false;
          this.scrollingOutput.emit(false);
         });
       }
    
       get scrolling() {
          return this.isScrolling;
       }
    }
    

    Content&lt;ion-content&gt; 标记标签的类。

    【讨论】:

      【解决方案2】:

      你可以使用scrollIntoView函数:

      ionViewDidEnter(){
          let todayItem = document.getElementById('yourTodayItemId');
          todayItem.scrollIntoView(true);
      }
      

      但是这种方式有一些UX issues。请考虑使用它或编写自己的滚动功能以获得最佳用户体验。

      【讨论】:

      • 小心scrollIntoView。它不适用于带有 Ionic 4 应用程序的 iOS,可能是由于 Safari Mobile (?) 缺乏支持。
      猜你喜欢
      • 1970-01-01
      • 2017-09-30
      • 2019-01-01
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 2011-06-21
      相关资源
      最近更新 更多