JS table 滚动

项目中有些场景需要table 进行滚动展示
获取table的高度
获取table的标题高度
获取table body 的高度

  scrollHandle() {
    var _this = this;
    if (_this.preTableInterval1) {
      clearInterval(_this.preTableInterval1);
    }
    if (this.$refs.preTable1 != "undefined") {
      var wrapH = document.querySelector(".pre_table").clientHeight;
      var theadH = document.querySelector(".pre_table thead").clientHeight;
      var tbodyH = document.querySelector(".pre_table tbody").clientHeight;
      var h = tbodyH + theadH - wrapH;
      if (h > 0) {
        _this.position1 = 0;
        _this.preTableInterval1 = setInterval(function() {
          if (_this.$refs.preTable1) {
            _this.position1 += 0.5;
            _this.$refs.preTable1.bodyWrapper.scrollTop = _this.position1;
            if (_this.position1 >= h) {
              _this.$refs.preTable1.bodyWrapper.scrollTop = 0;
              _this.position1 = 0;
              clearInterval(_this.preTableInterval1);
              _this.scrollHandle();
            }
          }
        }, 50);
      }
    }
  }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。