scrollIntoView()在使用普通JS时不起作用

时间:2018-12-05 02:37:06

标签: javascript typescript ionic-framework scrollview

我正在尝试使用scrollIntoView()来使页面根据特定条件滚动到某个元素。这是我的功能:

  continue() {
    if (!this.data.inputs.selectedPackagingIds.length) {
      this.error = 'Please select new packaging.'; // todo translate - use translation key
    } else if (this.isPackagingSuggested && !this.data.inputs.changeReasons.filter(r => { return r.selected }).length) {
      document.getElementById("scroll-view").scrollIntoView();
      this.error = 'Please select change reason.'; // todo translate
    } else {
      this.navCtrl.setRoot(LabelPrintTab, { data: this.data });
    }
  }

这是我的html:

<ion-content class="pc-nativeScannerPage">
 // Content appears in this area.
</ion-content>

<p id="scroll-view">Sentence to scroll to</p>

<ion-footer class="scroll-footer">
  <ion-row>
    <ion-col text-right>
      <span *ngIf="error" class="pc-continue-error">{{Error msg goes here }} </span>
      <button (click)="continue()" class="pc-primary" ion-button>{{ This button triggers the continue() function }}</button>
    </ion-col>
  </ion-row>
</ion-footer>

但是,没有任何反应。当此条件为真时,页面不会滚动到元素,而且我不知道为什么。有人有建议吗?

0 个答案:

没有答案