我有这个代码:
// gets the image size and position in order to make it fullscreen and centered.
getImageDim = function(img) {
var $img = new Image();
$img.src = img;
var $win = $(window),
w_w = $win.width(),
w_h = $win.height(),
r_w = w_h / w_w,
i_w = $img.width,
i_h = $img.height,
r_i = i_h / i_w,
new_w, new_h, new_left, new_top;
if (r_w > r_i) {
new_h = w_h;
new_w = w_h / r_i;
}
else {
new_h = w_w * r_i;
new_w = w_w;
}
return {
width: new_w,
height: new_h,
left: (w_w - new_w) / 2,
top: (w_h - new_h) / 2
};
}
任何人都可以帮助对此进行切片以完全理解吗?是什么r_w
?是什么r_i
?我们为什么要评估r_w > r_i
?我在最后看到了返回函数,但是这些、 和width
值height
将分配给哪个元素?分配这个有什么意义?提前致谢!left
top
$img.src = img;