微信小程序轮播图 图片高度自适应
2019-06-10 16:14
771 查看
wxml <view class='swiper-box'> <swiper wx:if="{{ imgUrls.length !== 0 }}" indicator-dots="true" autoplay="true" circular="true" style='{{bannerHeight}}'> <block wx:for="{{imgUrls}}" wx:key="key"> <swiper-item> <image src="{{item.img}}" bindtap='bannerimgfun' data-index="{{index}}" class="slide-image" mode="widthFix" /> </swiper-item> </block> </swiper> </view>
wxss .swiper-box{ width: 100%; margin: auto; } .swiper-box .slide-image{ width: 100%; }
js var that = ''; var query; Page({ data: { bannerHeight: '', imgUrls: [], status: true }, onLoad: function (options) { that = this; query = wx.createSelectorQuery(); this.getBannerImg(); }, getBannerImg() { //轮播数据请求成功响应到视图层 that.setData({ imgUrls: [ { "img": "https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640&h=200" }, { "img": "https://images.unsplash.com/photo-1551334787-21e6bd3ab135?w=640&h=200" }, ] }) if (that.data.status) { wx.createSelectorQuery().selectAll('.slide-image').boundingClientRect(function (rects) { console.log(rects) if (rects.length !== 0) { that.setData({ bannerHeight: "height:" + rects[0].height + "px" }); if (that.data.status) { that.getBannerImg(); setTimeout(() => { that.setData({ status: false }); }, 500) } } }).exec(); } } })
相关文章推荐
- 微信小程序之swiper轮播图中的图片自适应高度
- 微信小程序之swiper轮播图中的图片自适应高度的方法
- 微信小程序图片懒加载,图片高度自适应
- 微信小程序图片实现宽度100%,高度自适应
- 微信小程序轮播图的高度自适应问题
- 微信小程序实现图片高度自适应
- 微信小程序图片实现宽度100%,高度自适应
- 微信小程序实现banner图轮播(动态获取数据),自动获取图片高度
- 微信小程序 Image 图片实现宽度100%,高度自适应
- 微信小程序 swiper高度自适应
- 微信小程序 图片宽度自适应的实现
- 微信小程序图片轮播
- 微信小程序顶部导航栏自定义,根据不同手机自适应距离状态栏高度,防止标题栏高度歪歪扭扭
- 微信小程序 图片宽高自适应详解
- [微信小程序]根据图片宽高动态改变swiper(轮播图)组件宽高
- 微信小程序幻灯的swiper标签宽和高度自适应
- 微信小程序如何在设置轮播图时滑动可以完美衔接(图片最后一张和第一张可以衔接滑动)
- 微信小程序image图片自适应宽度比例显示的方法
- 微信小程序实现图片轮播功能
- 微信小程序swiper高度自适应方法