PullUp.vue 3.2 KB

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