0
像我有這樣的代碼:圍繞與jQuery
// 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;
有什麼意義?提前致謝!
這種類型的問題更適合http:// codereview .stackexchange.com –