zoukankan      html  css  js  c++  java
  • ionic3——ion-scroll无法使用scrollTo的问题

    在使用ionic3做返回置顶的时候,发现里边用了fixed absolute等一些定位的内容时,scrollTo,scrollTop,scrollLeft就失效了,可以使用scrollIntoView(),例子如下:

    <ion-scroll  #testScroll scrollY="true"  [ngStyle]="{height: announce_height+'px'}" style="100%">
                <div *ngIf="showScroll">暂无通告</div>
                <div (click)="" id="id{{i}}" *ngFor="let m of mess;let i = index">
                  <div>
                    {{m.content}}
                  </div>
                </div>
              </ion-scroll>

    这里重点是id="id{{i}}"动态生成的锚点;

    setTimeout(()=>{
                  var el = document.getElementById('id'+this.navParams.get('num'));//id0,id1...
                  el.scrollIntoView(true);
              },200);
    如果没有上述问题,可以使用:
    第二种方法:

    首先导入:

    import { Content } from 'ionic-angular';
    1
    然后获取content的实例:

    @ViewChild(Content) content: Content;
    1
    然后调用content的scrollToTop()

    toTop() {
    this.content.scrollToTop();
    }

    第三种方法:
    滚动到指定坐标位置,三个参数依次为坐标x,y,滚动时间(毫秒单位)。

    scrollTo(){
    this.content.scrollTo(0, 0, 300)
    }

    第二种的scrollToTop(),还有这个scrollTo(0, 0, 300)都是content的方法。更多详情请参考官网。我开始学的时候,就看到它是content标签,其他就不管了。后来再回去看时,发现还有很多有用的内容。这再次告诉我们,多看官网是没错的。

     
    参考地址:https://blog.csdn.net/qq993284758/article/details/78494003  ionic3实现3种返回顶部操作
                      https://www.jianshu.com/p/08cbad50dba3 
  • 相关阅读:
    cakephp异常机制
    你的效率是整理出来的——张一驰
    eclipse常用总结
    cakephp写Lib要点
    代码整洁之道-马丁-第3章 函数
    PHP静态方法如何编写
    编程常用工具
    代码大全(第二版)
    PHP实现AES对称加密
    【pytest】(三) pytest运行多个文件
  • 原文地址:https://www.cnblogs.com/lynna/p/12530003.html
Copyright © 2011-2022 走看看