PullUp.vue 2.6 KB

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