加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

微信小程序swiper组件中图片自适应

发布时间:2020-12-14 19:44:35 所属栏目:资源 来源:网络整理
导读:index.wxml index.js swiper中默认高度150px,使用 bindchange="bindchange" style="height:{{imgheights[current]}}rpx;" ,使其高度变为当前选中图片的高度 其二,下面的单位为px而非rpx。 Page({ data: { image: [ 'http://img02.tooopen.com/images/201509

index.wxml


      
    
  

index.js

swiper中默认高度150px,使用bindchange="bindchange" style="height:{{imgheights[current]}}rpx;",使其高度变为当前选中图片的高度

其二,下面的单位为px而非rpx。


    
      
    
  
Page({
  data: {
    image: [
      'http://img02.tooopen.com/images/20150928/tooopen_sy_143912755726.jpg',activeColor: "#1472e0",auto:{},cur:0
  },imageLoad: function (e) {
    var imageWidth = e.detail.width,//获取图片真实宽度
        imageHeight = e.detail.height,Imagescale = imageWidth / imageHeight; //宽高比
    var autoWidth = '',//自适应高宽
        autoHeight = '';
    wx.getSystemInfo({
      success: function(res) {
        autoWidth = res.windowWidth; //设备屏幕宽度
        autoHeight = autoWidth / Imagescale; //计算图片自适应高 
      }
    });
    var image = this.data.auto;
    image[e.target.dataset.index] = {
      width: autoWidth,height: autoHeight
    }
    console.log(image);
    this.setData({
      auto:image
    })
  },bindchange: function (e) {
    this.setData({ cur: e.detail.current })
  }
})

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读