Requirements: Picture width<=330px,height<=150.
1, the use of max-width,max-height so that the proportion of the picture automatically scaling, code:
Copy Code code as follows:
img{max-width:330px;max-height:150px;}
Because IE6 does not support CSS max-width,max-height, JavaScript scripts are needed to control size in IE6.
2, with JavaScript script compatible IE6, code such as:
Copy Code code as follows:
var img_width = img. Offsetwidth;<br>var img_height = offsetheight;
var current_w = (150*img_width)/img_height;
var current_h = (330*img_height)/img_width;
if (img_height>150) {
if (img_width>330) {
D.css (img,{
width:330 + "px",
Height:current_h + "px"
})
}else{
D.css (img,{
Width:current_w + "px",
height:150 + "px"
})
}
}else{
if (img_width>330) {
D.css (img,{
width:330 + "px",
Height:current_h + "px"
})
}else{
D.css (img,{
Width:img_width + "px",
Height:img_height + "px"
})
}
}
"Note 1:d.css is KISSY.DOM.CSS, referring to the DOM method in the Kissy class library"
"NOTE 2: Use JavaScript to control the size of the picture page must wait for the picture to be fully loaded, so the code to be included in the Window.onload event, if the picture loading slowly, there may be a small flaw."