您的位置:首页 > 其它

浅谈 sencha 2.0 中image和carousel的图片自适应大小的应用

2012-07-28 03:58 239 查看
在sencha 2.0中,经常会用到xtype:image, 但是这个类型的使用,它的表现形式都是一个<div>,然后给把我们要显示的图片作为背景图片放入这个div中,这样,我们往往不好设置它的大小,因为图片是背景图片,高宽都不如<img>标签进行控制的好。

尤其是当我们使用xtype:carousel这个类型时,如果代码是这样:

xtype: 'carousel',
items: [{
xtype: 'image',
height: '100',
width: '100',
src: 'http://192.168.1.1/image.jpg'
},{
xtype: 'image',
height: '100',
width: '100',
src: 'http://192.168.1.1/image.jpg'
}]

这样,即使我们设置了高宽,但是图片都不会按大小进行缩放,反而是图片按这个大小进行裁剪,因为这样表现出来的是一个div里面的背景图片。因此,我们不妨不要直接在carousel的items里面直接写image,而是在items里面先定义一个panel,然后往这个panel里面填充,用html:"<img src='http://192.168.1.1/image.jpg'
style='max-height:200px;max-width:200px'>":就如代码:

xtype: 'carousel',
items: [{
xtype: 'panel',
html:"<img src='http://192.168.1.1/image.jpg' style='max-height:200px;max-width:200px'>"
},{
xtype: 'panel',
html:"<img src='http://192.168.1.1/image.jpg' style='max-height:200px;max-width:200px'>"
}]


这样把max-height和max-width设置为carousel的大小,那么图片就会自动缩放
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: