weex icon indicating copy to clipboard operation
weex copied to clipboard

how to make `image` widget match-parent ?

Open Rowandjj opened this issue 10 years ago • 2 comments

i use $getConfig() to fetch screen height,and then assign to image height.but it does not work,screen height is large than expects.

<template>
  <scroller>
    <image class="my_image" style="width:750;height:{{height}}" src = "http://img.alicdn.com/bao/uploaded/i2/2547343901/TB2bPxhjFXXXXcnXpXXXXXXXXXX_!!2547343901-0-paimai.jpg_400x400.jpg">
    </image>
  </scroller>
</template>

<style>

</style>

<script>
  var modal = require('@weex-module/modal');
  module.exports = {
    data:{
        height:''
    },
    methods : {
      ready: function(){
        var config = this.$getConfig();
        var screenHeight = config.env.deviceHeight;
        modal.toast({'message':'height:'+screenHeight,'duration':1});
        this.height = screenHeight;
      }
    }
  }
</script>

Rowandjj avatar Jun 13 '16 09:06 Rowandjj

@Rowandjj The deviceHeight gotten in this.$getConfig() is the real device height in pixel, not the height with 750-adapted.

So you should convert it to a 750-adapted height:

var screenHeight = 750 / config.env.deviceWidth * config.env.deviceHeight 

This may be a pretty inelegant way, but it can solve your problem.

cxfeng1-zz avatar Jun 13 '16 13:06 cxfeng1-zz

@cxfeng1 got it,thanks~

Rowandjj avatar Jun 14 '16 01:06 Rowandjj