PullUp.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <!-- 移动端上拉加载更多 -->
  3. <!--<a @click="scrollToTop" v-show="!hideToTop"><i class="iconfont icon-arrow-up icon-xlg"></i></a>-->
  4. </template>
  5. <script>
  6. // import { scrollTo } from '~utils/scroll'
  7. export default {
  8. data () {
  9. return {
  10. hideToTop: true
  11. }
  12. },
  13. props: {
  14. searchMore: {
  15. type: Boolean
  16. },
  17. allPage: {
  18. type: Number
  19. },
  20. page: {
  21. type: Number
  22. },
  23. fixId: {
  24. type: String,
  25. default: null
  26. },
  27. isValid: {
  28. type: Boolean,
  29. default: true
  30. },
  31. FixedEl: { // 获取元素区域内滚动高度
  32. type: Boolean,
  33. default: false
  34. }
  35. },
  36. mounted () {
  37. let _this = this
  38. _this.$nextTick(function () {
  39. let obj = this.fixId ? document.getElementById(this.fixId) : window
  40. if (obj) {
  41. obj.addEventListener('scroll', function () {
  42. if (_this.isValid) {
  43. _this.scroll()
  44. }
  45. }, false)
  46. }
  47. })
  48. },
  49. methods: {
  50. scroll: function () {
  51. let scrolled = 0
  52. let height = 0
  53. let availHeight = window.screen.availHeight
  54. // console.log(document.getElementById(this.fixId).scrollHeight)
  55. // console.log(document.getElementById(this.fixId).scrollTop + window.screen.availHeight + '-------')
  56. if (this.fixId) {
  57. let obj = document.getElementById(this.fixId)
  58. height = obj.scrollHeight
  59. let _scrollHeight = 0.88
  60. if (this.$route.fullPath.indexOf('order') > -1) {
  61. _scrollHeight = 1.26
  62. }
  63. scrolled = obj.scrollTop - document.body.scrollWidth / 750 * 100 * _scrollHeight
  64. } else {
  65. height = document.body.scrollHeight
  66. scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  67. } if (this.FixedEl) {
  68. let obj = document.getElementById(this.fixId)
  69. // availHeight = document.getElementById(this.fixId).clientHeight + 50
  70. if (obj.clientHeight + obj.scrollTop >= obj.scrollHeight && !this.searchMore && this.page < this.allPage) {
  71. this.getMore()
  72. }
  73. } else if (Math.ceil(scrolled + availHeight) >= height && !this.searchMore && this.page < this.allPage) {
  74. this.getMore()
  75. }
  76. },
  77. getMore: function () {
  78. if (!this.searchMore) {
  79. this.$emit('pullUpAction')
  80. }
  81. },
  82. scrollToTop () {
  83. // console.log(1)
  84. let el = document.querySelector('.mobile-fix-content')
  85. if (el) {
  86. el.scrollTop = 0
  87. }
  88. // console.log(el.scrollTop)
  89. // scrollTo(el ? '.mobile-fix-content' : 'body', 100, {offset: el ? el.scrollTop : null})
  90. }
  91. }
  92. }
  93. </script>
  94. <style lang="scss" scoped>
  95. a {
  96. position: fixed;
  97. right: .1rem;
  98. bottom: 1.1rem;
  99. background: rgba(0,0,0,.4);
  100. color: #fff;
  101. width: .88rem;
  102. height: .88rem;
  103. line-height: .88rem;
  104. border-radius: 100%;
  105. text-align: center;
  106. i {
  107. font-size: .46rem;
  108. }
  109. }
  110. </style>