項(xiàng)目中有些場(chǎng)景需要table 進(jìn)行滾動(dòng)展示
獲取table的高度
獲取table的標(biāo)題高度
獲取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);
}
}
}