小程序swiper根據頁面長度滑動的案例:
在對應的js文件中添加以下代碼:
get_wxml: function (className, callback) {
wx.createSelectorQuery().selectAll(className).boundingClientRect(callback).exec()
},
//獲取節點信息
this.get_wxml(`#cont` + current, (rects) => {
console.log(rects)
let newHeight = rects[0].height
this.setData({
heights: newHeight
})
})
在對應的wxml文件中添加以下代碼:
<view class="goods_info_box">
<view class="tba_contain">
<!-- 導航欄 -->
<scroll-view class="tab" scroll-x scroll-left="{{tabScroll}}" scroll-with-animation="true">
<block wx:for="{{menuList}}" wx:key="index">
<view class="tab-item {{currentTab == index ? 'active' : ''}}" data-current="{{index}}" bindtap='clickMenu' style="width:{{100/menuList.length}}%">
<text>{{item.name}}</text>
</view>
</block>
</scroll-view>
<!-- 頁面 -->
<swiper class="list_content" duration="500" current="{{currentTab}}" bindchange="changeContent" style="height:{{heights}}px">
<swiper-item class="content-item" wx:for="{{menuList}}" wx:key="index" >
<view >
<text class='reason_txt'> {{item.name}}</text>
</view>
<view id='cont{{index}}' class="swiper-com" style="color:#000;font-size:40rpx;">
<rich-text nodes="{{item.content}}" ></rich-text>
</view>
</swiper-item>
</swiper>
</view>
</view>