小程序 swiper 高度自适应(js写法 一看就会)

小程序 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 () {

    }
})
  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 9
    评论
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值