php手机底部加载分页,实现分页组件悬浮在页面底部

已经实现了,分享下方法。

整体思路是 :

获取窗口高度,再获取table高度。如果table的高度>(窗口高度 - 上边导航栏的高度)那说明数据超出屏幕,则将分页器绝对定位到底部,否则跟随table底部即可。

详细步骤如下:

第一步 :document.documentElement.clientHeight 获取浏览器整体的高度。

这里要注意:我用的vue,所以在mounted中 用onresize监听窗口变化

window.onresize = () => {

return (() => {

window.fullHeight = document.documentElement.clientHeight

_this.fullHeight = window.fullHeight

_this.setPaginationStyle()

})()

}

第二步 :给你的table定义一个ref属性,this.$refs.myTable.$el.clientHeight 拿到table的高度。

这里要注意下 this.$refs.myTable.$el.clientHeight拿到的高度是数据填充之前获取到的(这里坑了我小半天),所以我在vue的updated钩子函数中再次获取一次。具体方法如下:

/**

* 设置分页位置的方法

*/

setPaginationStyle:function () {

console.log('myTable',this.$refs.myTable)

console.log('clientHeight',this.$refs.myTable.$el.offsetHeight)

console.log('fullHeight',this.fullHeight)

//浏览器高度小于 704 直接定位到底部

if(this.fullHeight < 704){

this.paginationStyle = 'background-color: white;position: fixed;bottom: 0; width: 100%; z-index: 100;'

this.myTableStyle = 'margin-bottom:35px'

}else {

//table宽度小于 浏览器高度 - (面包屑 + 导航栏的高度)说明需要固定位置

if(this.$refs.myTable.$el.clientHeight < this.fullHeight - 320 ){

this.paginationStyle = 'background-color: white'

this.myTableStyle = 'margin-bottom:0px'

}else {

this.paginationStyle = 'background-color: white;position: fixed;bottom: 0; width: 100%; z-index: 100;'

this.myTableStyle = 'margin-bottom:35px'

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值