小程序 swiper 高度自适应
代码:
wxml 页面:
<swiper class="swiper" style="height: {{height+'px'}}" indicator-dots="{{indicatorDots}}" autoplay="{{autoplay}}" interval="{{interval}}" duration="{{duration}}">
<swiper-item>
<view class="timu_list">
这里是内容
<view>很长很长的内容</view>
</view>
</swiper-item>
</swiper>
js 页面:
// pages/timu/timu.js
Page({
/**
* 页面的初始数据
*/
data: {
// 屏幕高度
height:0,
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.height()
},
// 获取轮播滑动的 高度
height:function(){
let that = this;
var query = wx.createSelectorQuery();
query.select('.timu_list').boundingClientRect(function (rect) {
that.setData({
// 获取要循环标签的高度
height: rect.height ,
})
// console.log(that.data.height);
}).exec();
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
onReady: function () {
},
/**
* 生命周期函数--监听页面显示
*/
onShow: function () {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide: function () {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload: function () {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom: function () {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage: function () {
}
})