日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

小程序swiper(tab)高度自适应

發布時間:2025/4/16 57 豆豆
生活随笔 收集整理的這篇文章主要介紹了 小程序swiper(tab)高度自适应 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

swiper高度問題一直困擾我。今天終于有時間來解決一下。因為他的高度不能固定死,寫死其他數據展示不完全,不寫或者100%,auto都不行。翻了一堆資料也查了很多,最后總結一下。
1.很多人都說用一種方法。就是高度*數量,也就是所說的獲取數據數組長度,根據數據長度來動態改變每頁的長度,因為字號啊什么的在各個手機顯示不一定都相同,總感覺不是解決問題的最佳方法。
2.使用Swiper+scroll-view
先設置swiper高度

<swiper style="height: {{clientHeight?clientHeight+'px':'auto'}}" class='videoSwiper' current="{{currentTab}}" duration="200" bindchange="swiperchange"></swiper>

在swiper-item中嵌套一個scroll-view

<swiper-item ><scroll-view scroll-y="{{true}}" style="height: {{clientHeight?clientHeight+'px':'auto'}}" bindscrolltolower="scrollbot"></scroll-view> </swiper-item >

在js中獲取設備可視窗口高度(我是寫在onload里的)

onLoad:function(){var that = thiswx.getSystemInfo({success: function (res) {that.setData({clientHeight: res.windowHeight});}})}

切換的js

swiperchange: function (e) {var that = thisconsole.log(e.detail.current)that.setData({'currentTab': e.detail.current})},

總結

以上是生活随笔為你收集整理的小程序swiper(tab)高度自适应的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。