美文网首页
ionic3——ion-scroll无法使用scrollTo的问

ionic3——ion-scroll无法使用scrollTo的问

作者: 一只飞 | 来源:发表于2018-02-26 17:35 被阅读0次

首先,我本来是想在ion-scroll中加个锚点,然后触发事件滚动到指定锚点。
在ionic1中可以:

 $location.hash(k);
 $ionicScrollDelegate.anchorScroll();

感觉ionic3应该也有类似方法吧,然后看了官方文档https://ionicframework.com/docs/api/components/scroll/Scroll/
啥也没有啊!!!
只能google了,发现scrollTo,scrollTop,scrollLeft等方法都不行。
最后,用scrollIntoView这个方法。
具体:

<ion-scroll  #testScroll scrollY="true"  [ngStyle]="{height: announce_height+'px'}" style="width: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);

如果没看懂呢,可能我表达有问题哈,看这个
https://stackoverflow.com/questions/44099796/how-can-i-use-content-scrollto-for-ion-scroll-in-ionic2

相关文章

网友评论

      本文标题:ionic3——ion-scroll无法使用scrollTo的问

      本文链接:https://www.haomeiwen.com/subject/mbwyxftx.html