码迷,mamicode.com
首页 > 其他好文 > 详细

图片自适应不变形

时间:2015-03-30 10:58:48      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:

<script type="text/javascript">
function ResizeImage(_image, max_width, max_height) {
//var max_width = 300;
//var max_height = 300;
var _width = _image.width;
var _height = _image.height;
var width_ratio = _width / max_width;
var height_ratio = _height / max_height;
//alert("Width ratio:" + _width + ", Height Ratio:" + _height);

if ( width_ratio >= height_ratio && _image.width > max_width) {
_image.width = max_width;
}
else if (height_ratio > width_ratio && _image.height > max_height) {
_image.height = max_height;
}
}
</script>


--------------------------方法二--------------------------------------

HTML Image Auto Resize, HTML图片大小自动调整


.ImageStyle {
max-height:300px;
max-width:300px;
width:expression( (this.width > 300 && this.width > this.height) ? ‘300px‘: this.width+‘px‘);
height:expression( (this.height > 300 && this.height > this.width) ? ‘300px‘: this.height+‘px‘);
border: 0px;
vertical-align: middle;
}

图片自适应不变形

标签:

原文地址:http://www.cnblogs.com/hupan508/p/4377242.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!