Skip to content

Commit de38d4e

Browse files
committed
Optimize the logic to calculate current distance
1 parent e3b8b69 commit de38d4e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/components/InfiniteLoading.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,18 @@
4040
* @return {Number} distance
4141
*/
4242
function getCurrentDistance(elm) {
43+
const styles = getComputedStyle(elm === window ? document.body : elm);
4344
const innerHeight = elm === window
4445
? window.innerHeight
45-
: parseInt(getComputedStyle(elm).height, 10);
46+
: parseInt(styles.height, 10);
4647
const scrollHeight = elm === window
4748
? document.body.scrollHeight
4849
: elm.scrollHeight;
4950
const scrollTop = isNaN(elm.scrollTop) ? elm.pageYOffset : elm.scrollTop;
51+
const paddingTop = parseInt(styles.paddingTop, 10);
52+
const paddingBottom = parseInt(styles.paddingBottom, 10);
5053
51-
return scrollHeight - innerHeight - scrollTop;
54+
return scrollHeight - innerHeight - scrollTop - paddingTop - paddingBottom;
5255
}
5356
5457
export default {

0 commit comments

Comments
 (0)