weex 怎么等比缩放图片?

新手上路,请多包涵

问题描述

需要图片按照比例缩放,

问题出现的环境背景及自己尝试过哪些方法

我有试过在@load函数内进行操作,但是效果不理想

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)
<template>

<image :src="val.primary_pic_url" :ref="'limg'+i" @load="leftimg(i,$event)" class='img' ></template>

</html>
<script>
leftimg(i,event){

      var that=this;
      const view = that.$refs['limg'+i];
      if(view[0].ref == event.target.ref){
        if(WXEnvironment.platform != 'Web'){
          // that.msg=view;
          // this.msg1=event;
          // 365px
          var rqwidth=365;
          var width=event.size.naturalWidth,height=event.size.naturalHeight;
          var ratio = rqwidth/width;
          // that.msg=ratio;
          width = ratio*width;
          height = ratio*height;
          this.testh=height;
          this.testw=width;
          animation.transition(view,{
            styles:{
              width: width+'px',
              height: height+'px'
            },
            duration: 0,
            timingFunction: 'ease',
            delay: 0,
            needLayout:true
          }, function(){})


        }
      }
    },

</script>

你期待的结果是什么?实际看到的错误信息又是什么?

阅读 2.5k
1 个回答
新手上路,请多包涵

leftimg(i,event){

      var that=this;
      const view = that.$refs['limg'+i];
      if(view[0].ref == event.target.ref){
        if(WXEnvironment.platform != 'Web'){
          that.msg=view;
          // this.msg1=event;
          // 365px
          var rqwidth = 365;
          var width = event.size.naturalWidth;
          var height = event.size.naturalHeight;
          var ratio = rqwidth/width;
          // that.msg=ratio;
          width = ratio*width;
          height = ratio*height;
          this.testh = height;
          this.testw = width;
          animation.transition(view[0],{
            styles:{
              width: width+'px',
              height: height+'px'
            },
            duration: 0,
            // timingFunction: 'ease',
            delay: 0,
            needLayout:true
          }, function(){var n=that.n;n++;that.n=n})


        }
      }
    },
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进