Skip to content

Commit a12d719

Browse files
committed
[fix] optimize scroller action when new DOM's height is too small which generated by load's new data
1 parent 92d03dc commit a12d719

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ temp/
55
node_modules/
66
npm-debug.log
77
yarn-error.log
8-
yarn.lock
8+
yarn.lock
9+
stats.json

packages/Scroller/src/Scroller.vue

+14-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
<div class="wd-scroller-no-infinite-loading-text">{{noDataText}}</div>
3434
</div>
3535
</template>
36-
<template v-else>
36+
<template v-else-if="showLoadingState">
3737
<div class="wd-scroller-infinite-load-tip-wrap" v-show="infiniteLoadingState !== 1">
3838
<div class="wd-scroller-bottom-text">{{loadText}}</div>
3939
</div>
@@ -95,6 +95,7 @@ export default {
9595
noRefresh: false,
9696
noRefreshStyle: false,
9797
noLoad: false,
98+
showLoadingState: true,
9899
$scrollTarget: null,
99100
$slotWrapper: null,
100101
render: null,
@@ -322,6 +323,18 @@ export default {
322323
},
323324
finishInfiniteLoading() {
324325
this.infiniteLoadingState = 0
326+
/**
327+
* 如果未拉来数据,或者新 DOM 高度过低,调整 scroll 位置避免露出底部提示文字
328+
*/
329+
let transformY = -(translateUtils.getElementTranslate(this.$refs.content).top)
330+
let contentHeight = this.$refs.slotWrapper.getBoundingClientRect().height
331+
if(this.containerHeight + transformY > contentHeight) {
332+
this.showLoadingState = false
333+
this.scroller.scrollTo(0, contentHeight - this.containerHeight, true)
334+
setTimeout(() => {
335+
this.showLoadingState = true
336+
}, this.animationDuration)
337+
}
325338
},
326339
noMoreRefresh() {
327340
this.noRefresh = true

src/utils/translate.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ let getTranslate = function(element) {
3939
}
4040

4141
let transform = element.style[transformProperty]
42-
let matches = /translate\(\s*(-?\d+(\.?\d+?)?)px,\s*(-?\d+(\.\d+)?)px\)\s*translateZ\(0px\)/g.exec(transform)
43-
if (matches) {
42+
let matches = transform.match(/translate3d\(\s*(-?\d+\.?\d*)px,\s*(-?\d+\.?\d*)px,.*\)/)
43+
if(matches) {
4444
result.left = +matches[1]
45-
result.top = +matches[3]
45+
result.top = +matches[2]
4646
}
4747

4848
return result

0 commit comments

Comments
 (0)