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, }) }, })