Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
chore: add the topScrollPos prop to check pos when scroll top
  • Loading branch information
snowyu committed Oct 2, 2018
commit ed926e6bd047868c7bc47a78df11291abc8df27d
17 changes: 15 additions & 2 deletions src/components/InfiniteLoading.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,12 @@ function hasClass(element, className) {

function restoreScrollPos() {
if (this.lastHeight) {
const vClientHeight = this.scrollParent.clientHeight;
let vPos = this.topScrollPos;
if (vPos <= 1) {
vPos *= this.scrollParent.clientHeight;
}
const vOffset = this.scrollParent.scrollHeight - this.lastHeight;
if (vOffset >= vClientHeight) {
if (vOffset >= vPos) {
this.scrollParent.scrollTop = vOffset + this.distance;
} else {
this.scrollParent.scrollTop = this.distance + 1;
Expand Down Expand Up @@ -146,6 +149,16 @@ export default {
infiniteWrapperClass: {
type: String,
},
/*
topScrollPos for direction is 'top'
pos = clientHeight * value when value in [0, 1]
pos = value when value > 1
*/
topScrollPos: {
type: Number,
validator: value => value >= 0,
default: 1,
},
},
mounted() {
this.scrollParent = this.getScrollParent();
Expand Down