weex
weex copied to clipboard
how to make `image` widget match-parent ?
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 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 got it,thanks~