|
39 | 39 | /**
|
40 | 40 | * get current distance from footer
|
41 | 41 | * @param {DOM} elm scroll element
|
| 42 | + * @param {String} dir calculate direction |
42 | 43 | * @return {Number} distance
|
43 | 44 | */
|
44 |
| - function getCurrentDistance(elm) { |
45 |
| - const styles = getComputedStyle(elm === window ? document.body : elm); |
46 |
| - const innerHeight = elm === window |
47 |
| - ? window.innerHeight |
48 |
| - : parseInt(styles.height, 10); |
49 |
| - const scrollHeight = elm === window |
50 |
| - ? document.body.scrollHeight |
51 |
| - : elm.scrollHeight; |
| 45 | + function getCurrentDistance(elm, dir) { |
| 46 | + let distance; |
52 | 47 | const scrollTop = isNaN(elm.scrollTop) ? elm.pageYOffset : elm.scrollTop;
|
53 |
| - const paddingTop = parseInt(styles.paddingTop, 10); |
54 |
| - const paddingBottom = parseInt(styles.paddingBottom, 10); |
55 |
| -
|
56 |
| - return scrollHeight - innerHeight - scrollTop - paddingTop - paddingBottom; |
| 48 | + if (dir === 'top') { |
| 49 | + distance = scrollTop; |
| 50 | + } else { |
| 51 | + const styles = getComputedStyle(elm === window ? document.body : elm); |
| 52 | + const innerHeight = elm === window |
| 53 | + ? window.innerHeight |
| 54 | + : parseInt(styles.height, 10); |
| 55 | + const scrollHeight = elm === window |
| 56 | + ? document.body.scrollHeight |
| 57 | + : elm.scrollHeight; |
| 58 | + const paddingTop = parseInt(styles.paddingTop, 10); |
| 59 | + const paddingBottom = parseInt(styles.paddingBottom, 10); |
| 60 | + distance = scrollHeight - innerHeight - scrollTop - paddingTop - paddingBottom; |
| 61 | + } |
| 62 | + return distance; |
57 | 63 | }
|
58 | 64 |
|
59 | 65 | export default {
|
|
78 | 84 | },
|
79 | 85 | onInfinite: Function,
|
80 | 86 | spinner: String,
|
| 87 | + direction: { |
| 88 | + type: String, |
| 89 | + default: 'bottom', |
| 90 | + }, |
81 | 91 | },
|
82 | 92 | mounted() {
|
83 | 93 | this.scrollParent = getScrollParent(this.$el);
|
|
0 commit comments