PullUp.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. },
  32. mounted () {
  33. let _this = this
  34. _this.$nextTick(function () {
  35. let obj = this.fixId ? document.getElementById(this.fixId) : window
  36. if (obj) {
  37. obj.addEventListener('scroll', function () {
  38. if (_this.isValid) {
  39. _this.scroll()
  40. }
  41. }, false)
  42. }
  43. })
  44. },
  45. methods: {
  46. scroll: function () {
  47. let scrolled = 0
  48. let height = 0
  49. // console.log(document.getElementById(this.fixId).scrollHeight)
  50. // console.log(document.getElementById(this.fixId).scrollTop + window.screen.availHeight + '-------')
  51. if (this.fixId) {
  52. let obj = document.getElementById(this.fixId)
  53. height = obj.scrollHeight
  54. let _scrollHeight = 0.88
  55. if (this.$route.fullPath.indexOf('order') > -1) {
  56. _scrollHeight = 1.26
  57. }
  58. scrolled = obj.scrollTop - document.body.scrollWidth / 750 * 100 * _scrollHeight
  59. } else {
  60. height = document.body.scrollHeight
  61. scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
  62. }
  63. // this.hideToTop = scrolled <= window.screen.availHeight
  64. // console.log(this.hideToTop)
  65. // console.log(this.allPage)
  66. // console.log(this.page)
  67. if (Math.ceil(scrolled + window.screen.availHeight) >= height && !this.searchMore && this.page < this.allPage) {
  68. this.getMore()
  69. }
  70. },
  71. getMore: function () {
  72. if (!this.searchMore) {
  73. this.$emit('pullUpAction')
  74. }
  75. },
  76. scrollToTop () {
  77. // console.log(1)
  78. let el = document.querySelector('.mobile-fix-content')
  79. if (el) {
  80. el.scrollTop = 0
  81. }
  82. // console.log(el.scrollTop)
  83. // scrollTo(el ? '.mobile-fix-content' : 'body', 100, {offset: el ? el.scrollTop : null})
  84. }
  85. }
  86. }
  87. </script>
  88. <style lang="scss" scoped>
  89. a {
  90. position: fixed;
  91. right: .1rem;
  92. bottom: 1.1rem;
  93. background: rgba(0,0,0,.4);
  94. color: #fff;
  95. width: .88rem;
  96. height: .88rem;
  97. line-height: .88rem;
  98. border-radius: 100%;
  99. text-align: center;
  100. i {
  101. font-size: .46rem;
  102. }
  103. }
  104. </style>