all files / src/infiniteScroll/ infiniteScroll.vue

0% Statements 0/10
0% Branches 0/12
100% Functions 0/0
0% Lines 0/9
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58                                                                                                                   
<template>
<div class="mu-infinite-scroll">
  <circular v-show="loading" :size="24"></circular>
  <span v-show="loading" class="mu-infinite-scroll-text">{{loadingText}}</span>
</div>
</template>
 
<script>
import circular from '../internal/circular'
import Scroll from '../internal/scroll'
export default {
  name: 'mu-infinite-scroll',
  mixins: [Scroll],
  props: {
    loading: {
      type: Boolean,
      default: false
    },
    loadingText: {
      type: String,
      default: '正在加载。。。'
    }
  },
  methods: {
    onScroll () {
      if (this.loading) return
      const scroller = this.scroller
      const isWindow = scroller === window
      const scrollTop = isWindow ? scroller.scrollY : scroller.scrollTop
      const scrollHeight = isWindow ? document.documentElement.scrollHeight || document.body.scrollHeight : scroller.scrollHeight
      let h = scrollHeight - scrollTop - 5
      let sh = isWindow ? window.innerHeight : scroller.offsetHeight
      if (h <= sh) {
        this.$emit('load')
      }
    }
  },
  components: {
    circular
  }
}
</script>
 
<style lang="css">
.mu-infinite-scroll{
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 8px;
  line-height: 36px;
  width: 100%;
}
.mu-infinite-scroll-text{
  margin-left: 16px;
  font-size: 16px;
}
</style>