fix: zoom error when pics res higher than screens res

This commit is contained in:
冯志浩 2016-12-19 22:58:09 +08:00
parent 5e45a8e130
commit d1abef32bc
2 changed files with 8 additions and 7 deletions

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
node_modules/
dist/
lib/
lib/
.DS_STORE

View File

@ -113,12 +113,12 @@ export default class ViewerCore extends React.Component<ViewerProps, ViewerCoreS
getImgWidthHeight(imgWidth, imgHeight) {
let width = 0;
let height = 0;
let aspectRatio = imgWidth / imgHeight;
if (aspectRatio > 1) {
width = Math.min(this.containerWidth * .8, imgWidth);
height = (width / imgWidth) * imgHeight;
}else {
height = Math.min((this.containerHeight - this.footerHeight) * .8, imgHeight);
let maxWidth = this.containerWidth * .8;
let maxHeight = (this.containerHeight - this.footerHeight) * .8;
width = Math.min(maxWidth, imgWidth);
height = (width / imgWidth) * imgHeight;
if (height > maxHeight) {
height = maxHeight;
width = (height / imgHeight) * imgWidth;
}
return [width, height];