(新手)scrollView检查十几遍不知哪里错
发布于 6 年前 作者 guiyingzhu 10414 次浏览 来自 问答

<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

    })

  }

})

2 回复

比如你order是 [1,2,3],第三次循环的时候,i = 2, i+1 = 3 而 order[3]是没有定义的,就报错啦

妹子 哪呢?🤤

回到顶部