jquery to achieve proportional scaling of pictures

Source: Internet
Author: User

  with native JavaScript implementation of the scale scaling, max-width and max-height in IE6 incompatible issues, today with jquery implementation of these problems
jquery part of the code
<script Type= "Text/javascript"
$ (document). Ready (function () {
var maxwidth=$ (". Imgbox"). width ();
$ ("img"). each (function () {
if (!$.support.style&&$.browser.msie&& ($.browser.version==6.0)) {// Determines when the browser is IE6
var imgwidth=$ (this). Width (),
var imgheight=$ (this). Height ();
var maxheight = maxwidth* Imgheight/imgwidth;
if (imgwidth>maxwidth) {
$ (this). CSS ("width", maxwidth). CSS ("height", maxheight);
}
}
})
})


</script>
CSS Partial code:
<style type= "text/css"
body{margin:0; padding:0;}
. box{width:700px; margin:0 Auto;}
. imgbox{background: #CCCCCC; *display:table-cell; width:400px; margin:10px auto; *font-size:350px; line-height : 400px; Text-align:center; Vertical-align:middle; padding:20px;}
img{border:0 none; max-width:400px; overflow:hidden; vertical-align:middle;}
</style>

HTML code:

<div class= "box"
<div class= "Imgbox"

</div>
</div>

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.