Scroll-View

1.wxml

scroll-view组件
class='section'>
class='section_title'>竖向滚动
'height:200rpx;background:red;'
scroll-y bindscrolltoupper='upper' 
bindscrolltolower='lower' 
bindscroll='scroll' 
scroll-into-view='{{toView}}' 
scroll-top='{{scrollTop}}' 
enable-back-to-top='true'
scroll-with-animation='true'>
'green' class='scroll-view-item' style='background:green;height:200rpx;'>
'yellow' class='scroll-view-item' style='background:yellow;height:200rpx;'>
'yellow' class='scroll-view-item' style='background:blue;height:200rpx;'>
'blue' class='scroll-view-item'>

class='btn-area'>



 

2.js

var order = ['green', 'yellow','blue'];

Page({
  data:{
    toView:'green',
    scrollTop:0
  },
  clickA(e){
    console.log('click container-A');
  },
  clickB(e) {
    console.log('click container-B');
  },
  clickC(e) {
    console.log('click container-C');
  },
  upper:function(e){
    console.log(e);
  },
  lower:function(e){
    console.log(e);
  },
  tap:function(e){
    console.log('我点击了切换滚动按钮!');
    if (this.data.toView == order[order.length-1])
    {
      this.setData({
        toView: order[0]
      });
      return;
    }
    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 + 20
    });
  }
})

 

感谢:https://www.bilibili.com/video/av61418389/?p=31

 

转载于:https://www.cnblogs.com/dzw159/p/11442757.html

你可能感兴趣的:(Scroll-View)