Skip to content

Commit c942911

Browse files
committed
Improve image preview position
1 parent fef01e7 commit c942911

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

app.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,10 @@ var app = function(){
9797
img.src = filepath;
9898
img.onload = function() {
9999
$(".file-view-img").attr('src', filepath);
100-
var imgWidth = $('.file-view-img').width();
101-
$(".file-view-wrapper").css('left', ($(document).width()-imgWidth)/2);
100+
var scale_width = 0.8 * $(document).width() / img.width;
101+
var scale_height = 0.8 * $(document).height() / img.height;
102+
var imgWidth = img.width * Math.min(scale_width, scale_height);
103+
$(".file-view-wrapper").css('left', ($(document).width() - imgWidth) / 2);
102104
$(".file-view-wrapper").css('width', imgWidth);
103105
$(".file-view-prev").css('display', 'block');
104106
$(".file-view-next").css('display', 'block');

0 commit comments

Comments
 (0)