Compatible with IE, Firefox pictures automatically scaling CSS and JS code sharing _javascript Skills

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.