代码之家  ›  专栏  ›  技术社区  ›  user2828442

获取尺寸。离子2中的contentTop属性值

  •  0
  • user2828442  · 技术社区  · 6 年前

    当我点击时,我试图从我的页面顶部获得多少滚动值。

    contentTop 返回的屏幕大小为662。 this.content.scrollHeight; 正在返回 1649

    我正在尝试使用:

    var isroll2 = this.content.getContentDimensions();
    console.log(isroll2.dimensions.contentTop);
    

    Official document here .

    我如何得到我需要的?

    home.ts

            ngAfterViewInit() {
    
                // Renderer2 used not Renderer, inject it before using
                this.renderer.listen('document', 'click', (e) => {
    
                  var isroll2 = this.content.getContentDimensions();
            // error in below line of code
                  console.log(isroll2.dimensions.contentTop);
    
        // if i use below code it always returns 0
        alert(isroll2.contentTop);
    
        //below code is giving me total height of my screen which is 662
              let element = this.content.getScrollElement();
              alert(element.clientHeight);
    
    // below line is returning 1649, which is total content length
     var iscroll =  this.content.scrollHeight;
    alert(iscroll);
    
            ...// code here
    
    0 回复  |  直到 6 年前