PullUp.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. if (Math.ceil(scrolled + window.screen.availHeight) >= height && !this.searchMore && this.page < this.allPage) {
  60. this.getMore()
  61. }
  62. },
  63. getMore: function () {
  64. if (!this.searchMore) {
  65. this.$emit('pullUpAction')
  66. }
  67. },
  68. scrollToTop () {
  69. // console.log(1)
  70. let el = document.querySelector('.mobile-fix-content')
  71. if (el) {
  72. el.scrollTop = 0
  73. }
  74. // console.log(el.scrollTop)
  75. // scrollTo(el ? '.mobile-fix-content' : 'body', 100, {offset: el ? el.scrollTop : null})
  76. }
  77. }
  78. }
  79. </script>
  80. <style lang="scss" scoped>
  81. a {
  82. position: fixed;
  83. right: .1rem;
  84. bottom: 1.1rem;
  85. background: rgba(0,0,0,.4);
  86. color: #fff;
  87. width: .88rem;
  88. height: .88rem;
  89. line-height: .88rem;
  90. border-radius: 100%;
  91. text-align: center;
  92. i {
  93. font-size: .46rem;
  94. }
  95. }
  96. </style>