<scroll-view style=‘height:200px’ bindscrolltolower=‘lower’ bindscroll=‘scroll’scroll-into-view="{{toView}}"scroll-top=’{{scrollTop}}'bindscrolltoupper=‘upper’ scroll-y=‘ture’>
<view id=‘red’ class=‘scroll-item bc_red’>red</view>
<view id=‘green’ class=‘scroll-item bc_green’>green</view>
<view id=‘blue’ class=‘scroll-item bc_blue’>blue</view>
<view id=‘pink’ class=‘scroll-item bc_pink’>pink</view>
<view id=‘yellow’ class=‘scroll-item bc_yellow’>yellow</view>
</scroll-view>
<button size=‘mini’ bindtap=‘tap’>点击一下</button>
var order = [‘red’,‘green’,‘blue’,‘pink’,‘yellow’]
Page({
/**
* 页面的初始数据
*/
data: {
toView:‘red’,
scrollTop:100
// 滚动的初始位置
},
upper:function(event){
console.log(‘我滚动到顶部了’)
},
lower:function(event){
console.log(‘我滚动到底部了’)
},
scroll:function(event){
console.log(‘我在滚动’);
// console.log(event);
// 滚动的信息
},
tap: function(e){
for(var i=0;i<order.length;++i){
if (order[i] === this.data.toView){
this.setData({
toView:order[i + 1]
})
break
}
}
},
tapMove: function(e){
this.setData({
scrollTop:this.data.scrollTop + 10
})
}
})