小程序swiper高度自适应
2018-02-08 22:20
459 查看
小程序swiper高度自适应[html]view plaincopydata: {
/图片
hdimg: [],
//是否采用衔接滑动
circular: true,
//是否显示画板指示点
indicatorDots: false,
//选中点的颜色
indicatorcolor: "#000",
//是否竖直
vertical: false,
//是否自动切换
autoplay: false,
//滑动动画时长毫秒
duration: 100,
//所有图片的高度
imgheights: [],
//图片宽度
imgwidth: 750,
//默认
current:0
[html]view plaincopyimageLoad: 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.push(imgheight)
this.setData({
imgheights: imgheights,
})
},
bindchange: function (e) {
console.log(e.detail.current)
this.setData({ current: e.detail.current})
}
[html]view plaincopy<view>
<swiperclass="swiper"indicator-dots="{{indicatorDots}}"vertical="{{vertical}}"autoplay="{{autoplay}}"duration="{{duration}}"bindchange="bindchange"circular="{{circular}}"style="height:{{imgheights[current]}}rpx;">
<blockwx:for="{{hdimg}}"wx:key="{{index}}">
<swiper-item>
<imagesrc="{{item}}"mode="aspectFit"bindload="imageLoad"
class=".itemimage"style="height:{{imgheights[current]}}rpx;width:{{imgwidth}}rpx;"/>
swiper-item>
block>
swiper>
view>
[html]view plaincopy.swiper {
width: 100%;
}
/图片
hdimg: [],
//是否采用衔接滑动
circular: true,
//是否显示画板指示点
indicatorDots: false,
//选中点的颜色
indicatorcolor: "#000",
//是否竖直
vertical: false,
//是否自动切换
autoplay: false,
//滑动动画时长毫秒
duration: 100,
//所有图片的高度
imgheights: [],
//图片宽度
imgwidth: 750,
//默认
current:0
[html]view plaincopyimageLoad: 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.push(imgheight)
this.setData({
imgheights: imgheights,
})
},
bindchange: function (e) {
console.log(e.detail.current)
this.setData({ current: e.detail.current})
}
[html]view plaincopy<view>
<swiperclass="swiper"indicator-dots="{{indicatorDots}}"vertical="{{vertical}}"autoplay="{{autoplay}}"duration="{{duration}}"bindchange="bindchange"circular="{{circular}}"style="height:{{imgheights[current]}}rpx;">
<blockwx:for="{{hdimg}}"wx:key="{{index}}">
<swiper-item>
<imagesrc="{{item}}"mode="aspectFit"bindload="imageLoad"
class=".itemimage"style="height:{{imgheights[current]}}rpx;width:{{imgwidth}}rpx;"/>
swiper-item>
block>
swiper>
view>
[html]view plaincopy.swiper {
width: 100%;
}
相关文章推荐
- 微信小程序之swiper轮播图中的图片自适应高度的方法
- 微信小程序swiper高度自适应方法
- 微信小程序幻灯的swiper标签宽和高度自适应
- 微信小程序之swiper轮播图中的图片自适应高度
- 移动web Swiper选项卡内容高度自适应
- 微信小程序轮播图的高度自适应问题
- 微信小程序实现图片高度自适应
- 微信小程序swiper组件实现图片宽度自适应
- 【小程序】<image>图片实现宽度100%时,高度自适应
- 微信小程序图片实现宽度100%,高度自适应
- 微信小程序swiper组件实现图片宽度自适应
- 微信小程序图片实现宽度100%,高度自适应
- 微信小程序 Image 图片实现宽度100%,高度自适应
- 微信小程序 swiper scroll-view height设置自适应 tab选项卡
- 自适应宽度和高度的Panel(js测试程序篇)
- iframe标签用法详解(属性、透明、自适应高度)
- 关于自适应label — 自适应宽/高度
- UILabel设置行间距之后的自适应高度
- iOS UIWebview自适应实际内容高度
- 三段式高度自适应页面布局