function openPreview image width height if width window innerWidth var

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
function openPreview(image, width, height) {
if (width > (window.innerWidth * 0.9)) {
var percent = 100 * (window.innerWidth * 0.9) / width;
width = (window.innerWidth * 0.9);
height = height * percent / 100;
}
while (height > (window.innerHeight * 0.95)) {
width = width / 1.01;
height = height / 1.01;
}
$(".imagePreview").css({display: "block"});
$("#previewSource").css({display: "block", marginTop: "-" + (height / 2).toString() + "px", marginLeft: "-" + (width / 2).toString() + "px"});
$("#previewSource").prop("src", image + "?seed=" + Math.random().toString());
$("#previewSource").prop("width", width);
$("#previewSource").prop("height", height);
}