Created
August 1, 2019 16:13
-
-
Save lili668668/e641ec5ee38d1fc97275f03b775dfcb9 to your computer and use it in GitHub Desktop.
計算表格位置的程式碼
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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