微信小程序: scrollView滑动到指定位置

 scroll.wxml:

<scroll-view class="banner" scroll-y scroll-into-view="{{cur}}" scroll-with-animation>
    <view class='item' id="one">1</view>
    <view class='item' id="two">2</view>
    <view class='item' id="three">3</view>
    <view class='item' id="four">4</view>
    <view class='item' id="five">5</view>
</scroll-view> 
<scroll-view class="point" scroll-x>
  <view class="item1" id="one" bindtap="scrollView">one</view>
  <view class="item1" id="two" bindtap="scrollView">two</view>
  <view class="item1" id="three" bindtap="scrollView">three</view>
  <view class="item1" id="four" bindtap="scrollView">four</view>
  <view class="item1" id="five" bindtap="scrollView">five</view>
</scroll-view>

scroll.js:

Page({
  data: {
    cur:"one" , //当前滚动的位置
  },
  scrollView(e){
    console.log(e);
    this.setData({
      cur: e.target.id,
    })
  },
})

 

posted @ 2022-02-15 14:50  云里知音  阅读(1009)  评论(0)    收藏  举报