wxml如下,滚动跳转必须设置height,stroll-top为滑块位置,不可省略。
<scroll-view scroll-y='true' scroll-with-animation enable-back-to-top style="height: {{h}}px;" scroll-into-view="{{toView}}" scroll-top="{{scrollTop}}">
<button class="top" bindtap="jumpmulu" size="mini">目录</button>>
<view id="intro" class="p">《微信小程序快速开发:视频指导版》.....
<view id="mulu">
目录
</view>
第1章 微信小程序介绍
....
</view>
<view class="jump">
<button size="mini" bindtap="jumptop">顶部</button>
</view>
</scroll-view>
Page({
data: {
toView: '',
scrollTop: 10
},
jumpmulu: function (e) {
this.setData({
toView: 'mulu'
})
},
jumptop: function (e) {
this.setData({
toView: 'intro'
})
},
onLoad: function (options){
var that=this
wx.getSystemInfo({
success: function (res) {
that.setData({
h:res.windowHeight
})
}
})
}
})