收藏
回答

图片怎么自适应宽高

框架类型 问题类型 API/组件名称 终端类型 操作系统 微信版本 基础库版本
小程序 需求 image 客户端 Android 1 1

<img style="max-width: 100px;max-height: 100px;" src="xxx.jpg">

web页面上的这种图片自适应方式怎么在小程序上实现


回答关注问题邀请回答
收藏

3 个回答

  • Special
    Special
    2018-03-26

    image 组件 mode 属性是否能满足需求?

    https://mp.weixin.qq.com/debug/wxadoc/dev/component/image.html

    2018-03-26
    有用
    回复
  • 李轩任
    李轩任
    2022-06-17

    <image class='imagelazy-load="truemode="aspectFitsrc="{{item.src}}" bindload='loadImgstyle="{{item.style}}"></image>

    loadImg(e) {
        let {
          width,
          height
        } = e.detail
    
        this.setData({
          ['item.style']: "width:" + width + "px;" + "height:" + height + 'px;'
        })
      },
    


    图片加载完了,有个回调,会给出来宽高,再设置到style上面去。

    2022-06-17
    有用
    回复
  • 李瀚鹏
    李瀚鹏
    2018-03-26

    不行,

    就aspectFit能自适应最大的宽高,不过会产生留白。


    2018-03-26
    有用
    回复
登录 后发表内容