Using JS to solve IE6 not support max-width,max-height problem

Source: Internet
Author: User

  This article mainly introduces the method of using JS to solve the problem that IE6 does not support max-width,max-height. Need friends can come to the reference, I hope to help you.

Today encountered a problem with JS to solve IE6 support max-width,max-height, just started with the jquery method to achieve, but has been not to get the value of CSS, such as   code as follows:   if ($. Browser.msie && $.browser.version = = 6.0)   {    var maxwidth = parseint ($ ('. Viewbigpic img '). CSS ( ' Max-width '));     $ ('. Viewbigpic img '). each (function () {      if ($ (this). Width () > maxwidth)         $ (this). Width (maxwidth);    });  }   Do not know what the reason is not to get the maximum value in the CSS, and then only use the original JS to achieve   JS code as follows:   code as follows: <script type= ' Text/javascript ' > function Setphotosize (elem, width, height) {<!--[if IE 6]> try{var image=new image (); image.src=elem.src; if (image . width>0 && image.height>0) {var rate = (Width/image.width < height/image.height)? width/image.width:h Eight/image.height; if (rate <= 1) {elem.width = image.width*rate; elem.height = image.height*rate;} else {elem.width = Image.width; elem. Height = image.height; }}catch (e) {} <!--[endif]--> } </SCThe HTML code for the Ript>   section is as follows:   code as follows: <div class= "Viewbigbox" >             <DIV class= "Viewbigpic" >             <p><img id= "Imgid" onload= "Setphotosize" (This, 730,470) "src=" images/viewshow.jpg "alt=" "/></p>             </div>   & nbsp        </div>   CSS style is as follows: The code is as follows:. viewbigbox{border:1px solid #e3e3e3; Background-color: #ff Ffff padding:1px;  margin-top:18px;} . viewbigpic{Background-color: #f7f7f7;p adding:20px 14px; viewbigpic p{display:table-cell;width:730px; line-height : 470px; Overflow:hidden; Vertical-align:middle; Text-align:center; height:470px;*font-size:390px;}  //Achieve the vertical center of the picture, mainly using the ratio of font-size and height. viewbigpic p img{vertical-align:middle; max-height:470px : 730px;}  

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.