| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- <template>
- <!-- 移动端上拉加载更多 -->
- <!--<a @click="scrollToTop" v-show="!hideToTop"><i class="iconfont icon-arrow-up icon-xlg"></i></a>-->
- </template>
- <script>
- // import { scrollTo } from '~utils/scroll'
- export default {
- data () {
- return {
- hideToTop: true
- }
- },
- props: {
- searchMore: {
- type: Boolean
- },
- allPage: {
- type: Number
- },
- page: {
- type: Number
- },
- fixId: {
- type: String,
- default: null
- },
- isValid: {
- type: Boolean,
- default: true
- }
- },
- mounted () {
- let _this = this
- _this.$nextTick(function () {
- let obj = this.fixId ? document.getElementById(this.fixId) : window
- obj.addEventListener('scroll', function () {
- if (_this.isValid) {
- _this.scroll()
- }
- }, false)
- })
- },
- methods: {
- scroll: function () {
- let scrolled = 0
- let height = 0
- // console.log(document.getElementById(this.fixId).scrollHeight)
- // console.log(document.getElementById(this.fixId).scrollTop + window.screen.availHeight + '-------')
- if (this.fixId) {
- let obj = document.getElementById(this.fixId)
- height = obj.scrollHeight
- scrolled = obj.scrollTop - 88
- } else {
- height = document.body.scrollHeight
- scrolled = document.documentElement.scrollTop || window.pageYOffset || document.body.scrollTop
- }
- // this.hideToTop = scrolled <= window.screen.availHeight
- // console.log(this.hideToTop)
- // console.log(this.allPage)
- // console.log(this.page)
- if (Math.ceil(scrolled + window.screen.availHeight) >= height && !this.searchMore && this.page < this.allPage) {
- this.getMore()
- }
- },
- getMore: function () {
- if (!this.searchMore) {
- this.$emit('pullUpAction')
- }
- },
- scrollToTop () {
- // console.log(1)
- let el = document.querySelector('.mobile-fix-content')
- if (el) {
- el.scrollTop = 0
- }
- // console.log(el.scrollTop)
- // scrollTo(el ? '.mobile-fix-content' : 'body', 100, {offset: el ? el.scrollTop : null})
- }
- }
- }
- </script>
- <style lang="scss" scoped>
- a {
- position: fixed;
- right: .1rem;
- bottom: 1.1rem;
- background: rgba(0,0,0,.4);
- color: #fff;
- width: .88rem;
- height: .88rem;
- line-height: .88rem;
- border-radius: 100%;
- text-align: center;
- i {
- font-size: .46rem;
- }
- }
- </style>
|