uniapp 微信小程序 Vue H5 跳转页面 定位 滑动到指定位置

微信小程序

需要看到滑动效果:

微信小程序滚动

scroll-into-view:值应为某子元素id(id不能以数字开头)。设置哪个方向可滚动,则在哪个方向滚动到该元素

<scroll-view v-if="showPage" scroll-y :scroll-into-view="scrollViewId" class="member-container">
......
  <div id="freight-coupon-box">
  </div>
  <div id="member-goods-list-box">
  </div>
</scroll-view>
onLoad (option) {
 if (option.toGoodsList) {
    this.toGoodsList = option.toGoodsList
  }
  if (option.toFreight) {
    this.toFreight = option.toFreight
  }
},
async onShow () {
   if (this.toGoodsList) {
     this.scrollViewId = 'member-goods-list-box'
   }
   if (this.toFreight) {
     this.scrollViewId = 'freight-coupon-box'
   }
},

在页面中需要点击滑动,使用uni.pageScrollTo

const query = uni.createSelectorQuery().in(this)
query.select('#goods_tab').boundingClientRect(data =>{
  this.goodsTabsTop = data.top
}).exec()
let top = this.goodsTabsTop + 70
uni.pageScrollTo({
  scrollTop: top,
  duration: 300
})

不需要看到滑动效果,直接定位:

在页面渲染之前提示加载中,不显示页面,等页面渲染之后,滚动完成再显示页面

async onShow () {
  if (this.toGoodsList) {
    this.scrollViewId = 'member-goods-list-box'
  }
  if (this.toFreight) {
    this.scrollViewId = 'freight-coupon-box'
  }
  this.showPage = true
},

H5

不需要看到滑动效果,直接定位:

H5滚动

<div v-if="showPage" class="member-container" ref="memberContainer">
......
  <div id="freight-coupon-box">
  </div>
  <div id="member-goods-list-box">
  </div>
</div>

.member-container {
  position: absolute;
  top: 0;
  bottom: 0;
  overflow: scroll;
}
async init () {
  await this.getUserInfo()
   await this.loadGoodsList()
   this.showPage = true
   this.refreshing = false

   if (this.toGoodsList) {
     this.$nextTick(() => {
       // 定位到prime专享折扣区域
       document.querySelector("#member-goods-list-box").scrollIntoView(true)
       this.$refs.memberContainer.scrollTop -= 15
       this.toGoodsList = false
     })
   }

   if (this.toFreight) {
     this.$nextTick(() => {
       // 定位到每月包邮区域
       document.querySelector("#freight-coupon-box").scrollIntoView(true)
       this.$refs.memberContainer.scrollTop -= 6
       this.toFreight = false
     })
   }
 },

往上滚动多少距离:

this.$refs.retailList.scrollTop -= 58
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值