在小程序中进行swiper自动适应高度

<view class='swiper'>
<swiper indicator-dots="{{indicatorDots}}" vertical="{{vertical}}" autoplay="{{autoplay}}" duration="{{duration}}" interval='{{interval}}' bindchange="bindchange" circular="{{circular}}" style="height:{{imgheights[current]+90}}rpx;" class="swiper-box">
<block wx:for='{{imgList}}' wx:key="{{index}}">
<swiper-item>
<image src="{{item.pic}}" data-id='{{index}}' class="slide-image" mode="widthFix" bindload="imageLoad" />
</swiper-item>
</block>
</swiper>
</view>
 
 
Page({
data: {
navbarInitTop: 0, //导航栏初始化距顶部的距离
isFixedTop: false, //是否固定顶部

//图片地址
imgList: ['https://www.sywebsoft.com/lh/img/b1.jpg','https://www.sywebsoft.com/lh/img/b2.jpg','https://www.sywebsoft.com/lh/img/b3.jpg'],
//是否采用衔接滑动
circular: true,
//是否显示画板指示点
indicatorDots: true,
//选中点的颜色
indicatorcolor: "#000",
//是否竖直
vertical: false,
//是否自动切换
autoplay: true,
//自动切换的间隔
interval: 5000,
//滑动动画时长毫秒
duration: 300,
//所有图片的高度
imgheights: [],
//图片宽度
imgwidth: 750,
//默认
current: 0,
inputValue: '', //搜索的内容
isxiangguan: false,
issousuodel:false,
showDialog: false,
showDialog2: false,
// gjz: '',
strceng: '0',
strcengname: '期数',
strcengnamex:'期数',

strceng2: '0',
strceng2name: '层数',
strceng2namex: '层数',

strbigid: '0',
strbigidname: '全部大类',
strbigidnamex: '全部大类',
 
strbigid2: '0',
strbigid2name: '全部小类',
strbigid2namex: '全部小类',


qishulist:[],
loucenglist:[],
fenleilist: [],
xiaofenleilist:[],
//分页用的
hidden: true, //隐藏表单控件
pageindex: 1, //当前请求数据是第几页
pagesize: 10, //每页数据条数
hasMoreData: true, //上拉时是否继续请求数据,即是否还有更多数据
contentlist: [], //获取的数据列表,以追加的形式添加进去

//分页用的
},
imageLoad: function(e) { //获取图片真实宽度
var imgwidth = e.detail.width,
imgheight = e.detail.height,
//宽高比
ratio = imgwidth / imgheight;
// console.log(imgwidth, imgheight)
//计算的高度值
var viewHeight = 750 / ratio;
var imgheight = viewHeight;
var imgheights = this.data.imgheights;
//把每一张图片的对应的高度记录到数组里
imgheights[e.target.dataset.id] = imgheight;
this.setData({
imgheights: imgheights
})
},
posted @ 2019-12-23 20:36  冷雨夜2019  阅读(490)  评论(0)    收藏  举报