这个
功能主要是为了
解决图片中内容页面太大而无法
支持,导致页面更难看到,它需要这样的代码,有需要的朋友可以
参考下。
要求:图片宽度≤600px,高度≤800。
1,使用最大宽度,最大高度自动缩放图片比例。
代码uff1a
复制代码代码如下所示:
img {最大宽度:600px;最大高度:800px;}
因为IE6不支持CSS的最大宽度、最大高度,你需要使用Javascript
脚本来
控制在IE6的大小。
2、IE6和Javascript脚本的兼容,如:
复制代码代码如下所示:
无功img_width = img.offsetwidth;VAR img_height = offsetheight;
无功current_w =(150×img_width) / img_height;
无功current_h =(330×img_height) / img_width;
如果(img_height > 150){
If (img_width>330) {
D.css(IMG,{
宽度:330 +
身高:current_h +PX
})
其他{ }
D.css(IMG,{
宽度:current_w +PX
高度:150 +
})
}
其他{ }
如果(img_width > 330){
D.css(IMG,{
宽度:330 +
身高:current_h +PX
})
其他{ }
D.css(IMG,{
宽度:img_width +PX
身高:img_height +PX
})
}
}
{注1:D.css是kissy.dom.css,参考在基西类库的DOM
方法)
{Note 2: using Javascript to control the size of the picture, the page must wait for the picture to be loaded completely, so the code should be included in the window.onload event. 如果图像加载
速度慢,可能会有一个小缺陷。
我们大家可以一起使用这两个,首先使用CSS,然后在后面添加JS。