Created
August 24, 2013 09:13
-
-
Save neekey/6327058 to your computer and use it in GitHub Desktop.
根据容器宽高和当前图片宽高确定适应宽高
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 根据容器宽高和当前图片宽高确定适应宽高 | |
* @param conW 容器宽度 | |
* @param conH 容器高度 | |
* @param imgW 图片宽度 | |
* @param imgH 图片高度 | |
* @returns {{w: *, h: *}} | |
*/ | |
getImgResize: function( conW, conH, imgW, imgH ){ | |
if( imgW <= conW && imgH <= conH ){ | |
return { | |
w: imgW, | |
h: imgH | |
}; | |
} | |
else { | |
var width = imgW * 1.0; | |
var height = imgH * 1.0; | |
if(( width / conW ) > ( height / conH )){ | |
var new_width = conW; | |
var new_height = parseInt( conW * height / width, 0); | |
} | |
else { | |
new_width = parseInt( conH * width / height, 0 ); | |
new_height = conH; | |
} | |
return { | |
w: new_width, | |
h: new_height | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment