Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
計算表格位置的程式碼
offsetBody () {
const scrollTop = (this.$refs.viewport as Element).scrollTop
const remainTopNumber = Math.floor(this.remainLineNumber / 2)
const remainTopHeight = remainTopNumber * this.renderLineHeight
const remainBottomHeight = (this.remainLineNumber - remainTopNumber) * this.renderLineHeight
const thresholdHeight = this.thresholdNumber * this.renderLineHeight
const gap = scrollTop - this.bodyTranslateY
const overThreshold = gap < remainTopHeight - thresholdHeight || gap > remainTopHeight + thresholdHeight
const isReachBottom = this.totalHeight - (scrollTop + this.viewportHeight) < remainBottomHeight
const isReachTop = scrollTop < remainTopHeight
if (isReachTop) {
this.offset = 0
this.bodyTranslateY = 0
} else if (isReachBottom) {
this.offset = this.items.length - this.renderLineNumber
this.bodyTranslateY = this.totalHeight - this.renderBodyHeight
} else if (overThreshold) {
this.offset = Math.floor(scrollTop / this.renderLineHeight) - remainTopNumber
this.bodyTranslateY = scrollTop - remainTopHeight
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment