This function is mainly to solve the content page in the picture too large, resulting in the page is more ugly, need such code, need friends can refer to the
Requirements: Picture width<=600px,height<=800.
1, the use of max-width,max-height to make pictures such as the scale of automatic scaling
Code:
Copy Code code as follows:
img{max-width:600px;max-height:800px;}
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."
All we can combine with these two are used together. First use CSS and then add JS back.