Skip to content

Commit 0029bec

Browse files
committed
feat(Scroller): 修复局部滚动虚拟滚动条位置计算问题
1 parent 9ffe480 commit 0029bec

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

src/fixed-table.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<div class='rel'>
3-
<div class='fixed-table-container' ref='content' @mouseover='mouseOver' @mouseout='mouseLeave'>
3+
<div class='fixed-table-container rel' ref='content' @mouseover='mouseOver' @mouseout='mouseLeave'>
44
<table v-if='isFixLeft' ref='leftClone' class='fixed-table table-clone left'>
55
<thead class='fixed-table corner' :style='theadStyle' :class='[{fixed: fixedTop}]'>
66
<slot name='leftThead'></slot>

src/scroll-x-bar.vue

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div ref='scroller' class='virtual-scroll overhidden' :style='style' v-show='bottom > 5 && virtualPercent < 1' @mousedown.self='barClickHandle'>
2+
<div ref='scroller' class='virtual-scroll overhidden' :style='style' @mousedown.self='barClickHandle'>
33
<div ref='bar' class="virtual-scroll-bar" :style='barLeft' @mousedown='barMouseDownHandle'></div>
44
</div>
55
</template>
@@ -18,7 +18,7 @@
1818
virtualMouseDownX: 0, // 鼠标按键x坐标
1919
virtualObserver: {},
2020
target: {}, // 滚动元素
21-
opacity: false, // 是否需要设置透明
21+
// opacity: false, // 是否需要设置透明
2222
bottom: 0, // 底部
2323
iframe: {} // iframe,用来监听resize
2424
}
@@ -45,7 +45,7 @@
4545
style() {
4646
return {
4747
transform: `translate3d(0px, ${-this.bottom}px, 0px)`,
48-
opacity: this.opacity ? 0 : 1
48+
opacity: this.bottom > 5 && this.virtualPercent < 1 ? 1 : 0
4949
}
5050
},
5151
scroller() {
@@ -104,28 +104,26 @@
104104
this.virtualObserver.disconnect()
105105
},
106106
methods: {
107-
setOpacityShow: timerFnc(function() {
108-
this.opacity = false
109-
}, 100),
110107
/**
111108
* @function
112109
* 监听全局滚动, 用来将虚拟滚动条固定在底部
113110
*/
114-
windowScrollHandle: timerFnc(
115-
function() {
116-
const { bottom } = this.target.getBoundingClientRect()
117-
let result = bottom - document.documentElement.clientHeight
118-
if (result < 0) {
119-
result = 0
120-
}
121-
this.bottom = result
122-
this.setOpacityShow()
123-
},
124-
100,
125-
function() {
126-
this.opacity = true
111+
windowScrollHandle: function() {
112+
const { bottom } = this.target.getBoundingClientRect()
113+
let offsetTop = 0
114+
if (this.scroller === window) {
115+
offsetTop = document.documentElement.clientHeight
116+
} else {
117+
offsetTop =
118+
this.scroller.clientHeight + this.scroller.getBoundingClientRect().top
127119
}
128-
),
120+
let result = bottom - offsetTop
121+
if (result < 0) {
122+
result = 0
123+
}
124+
this.bottom = result
125+
// this.setOpacityShow()
126+
},
129127
/**
130128
* @function
131129
* 目标滚动时候同步到虚拟滚动条位置
@@ -152,10 +150,7 @@
152150
this.windowScrollHandle()
153151
this.targetScrollHandle()
154152
},
155-
100,
156-
function() {
157-
this.opacity = true
158-
}
153+
100
159154
),
160155
/**
161156
* @event

0 commit comments

Comments
 (0)