ionic 页面滚动到底部方法

175 篇文章 1 订阅

强列推荐先看这篇译文《angular4 滚动事件

You’re trying to call a component method before it has fully rendered. You need to wait and call it after the view is fully loaded and all the elements have been created. 

export class HomePage {
  @ViewChild(Content) content: Content;

  constructor() {
  }

  ionViewDidEnter() {
    this.content.scrollToBottom();
  }
}

一、以上方法来自:ionic论坛Ion-scroll scrollToBottom 中 mhartington 回答,我们Tony大神也是用这中方法实现。

二、另外也可以参考这篇《ionic2/3 页面默认滚动到底部

两种方法:

 


1.使用 content 组件的 scrollToBottom() 方法,可以封装成函数使用:

//页面滚动到底部    
 

scrollToBottom() {      
    setTimeout(() => {        
        if(this.content.scrollToBottom){            
            this.content.scrollToBottom(0);        
        }      
    },200)    
}


2.使用 content 组件的 scrollDownOnLoad 属性:

<ion-content scrollDownOnLoad="true">

总结:
方法1体验不是很好,200毫秒的延迟视觉上可以看出来
方法2异步的请求有时候不能及时响应(可以请求第一次后存入本地存储里面),经过测试 虽然ionic3 中本地存储也是异步的,但是毫无延迟(可能是比较快)
推荐1+2一起使用

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值