需求:

实现A页面点击按钮wx.navigateToB页面并定位到view位置。

A.wxml

button bindtap='clickBtn'跳转/button

A.js

clickBtn: function(){    wx.navigateTo({        url: '../b/b?viewId=view4' // 参数viewId=定位的位置id    })}

B.wxml

scroll-view  scroll-into-view="{{toView}}" style='height:100%;' scroll-y="true" class="scr"    view id='view1' style='200px;'        textMy is View1/text    /view    view id='view2' style='200px;'        textMy is View2/text    /view    view id='view3' style='200px;'        textMy is View3/text    /view    view id='view4' style='200px;'        textMy is View4/text    /view    view id='view5' style='200px;'        textMy is View5/text    /view/scroll-view

这地方一定一定一定必须必须必须要注意:

1. scroll-into-view 即使是测试也不可写死(组件布局完成后,动态的改变这个scroll-into-view的值,才会跳到索引位置)

2. scroll-y="true" & 固定高度

B.js

Page({  data: {      toView:'' // 配置默认显示view  },  onLoad: function (options) {    var id = options.viewId // 定位view的id    this.setData({        toView:'id'    })  }})

以上只是大体实现思路,仅供参考~_~

TAG标签: 微信小程序scroll

http://www.xiaochengxub.com/read-104932.html