首页 > 微信 > 详细

微信小程序,scroll-view组件的使用,跳转到指定的锚点/定位跳转

时间:2020-09-17 13:47:26      阅读:287      评论:0      收藏:0      [点我收藏+]

 

scroll-view 属性设置:

scroll-y="true" 允许Y轴滚动;

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

scroll-with-animation="true" 在设置滚动条位置时使用动画过渡

注意: scroll-view 一定要设置 height: 的值 (px / rpx),否则无效

 

 

实现页面跳转,跳转到指定锚点位置

 

 index.wxml 页面创建跳转按钮 

技术分享图片
<!-- index.wxml -->

<view class="btn"  bindtap="jump" data-detail="detail0" > 跳到 detail0 锚点位置 </view>
<view class="btn"  bindtap="jump" data-detail="detail1" > 跳到 detail1 锚点位置</view>
<view class="btn"  bindtap="jump" data-detail="detail2" > 跳到 detail2 锚点位置 </view>
<view class="btn"  bindtap="jump" data-detail="detail3" > 跳到 detail3 锚点位置 </view>
技术分享图片

 

index.js

技术分享图片
// index.js
Page({
    data: {},
    // 跳详情页
    jump (event) {
        // 获取到跳转锚点id
        let detail = event.currentTarget.dataset.detail;

        wx:wx.navigateTo({
          url: ‘/pages/index/detail?detail=‘ + detail,  // 通过url传到跳转页面
        })
    },
})
技术分享图片

 

detail.wxml 跳转的页面

使用 scroll-view 

技术分享图片
<!-- detail.wxml -->
<view>
  
    <scroll-view scroll-y="true" style="height: {{height+‘px‘}};" scroll-into-view="{{ detail }}" scroll-with-animation="true"  >
      <view id="detail0" style="height: 500px" > detail0 </view>
      <view id="detail1" style="height: 500px" > detail1 </view>
        <view id="detail2" style="height: 500px" > detail2 </view>
        <view id="detail3" style="height: 500px" > detail3 </view>
</scroll-view> </view>
技术分享图片

 

scroll-view 属性设置:

scroll-y="true" 允许Y轴滚动;

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

scroll-with-animation="true" 在设置滚动条位置时使用动画过渡

注意: scroll-view 一定要设置 height: 的值 (px / rpx),否则无效

 

detail.js

技术分享图片
Page({

    data : {
        detail: ‘detail0‘, // 锚点id
        height: 0,  // 屏幕的高度
    },
    
    onLoad(options) {
        var that = this;
        console.log(options.detail);
        this.setData({
            height: wx.getSystemInfoSync().windowHeight, // 获取屏幕高度
            detail: options.detail  // 获取跳转过来的锚点id
        })
    },
})     
技术分享图片

 

微信小程序,scroll-view组件的使用,跳转到指定的锚点/定位跳转

原文:https://www.cnblogs.com/yuanjili666/p/13684231.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!