[英]Automatic image resizing if browser width =
我今天問了這個問題 ,並得到了一些很好的答案(感謝那些幫助我的人:))。
現在請看下面的代碼。 我100%確信調整大小部分可以工作,但是我的if / else語句不起作用(我仍然是JS新秀)。 我在上一個主題中也提到了這一點,但是有人說我寧願發布一個新問題。
(腳本應檢測到某人的瀏覽器寬度,以便可以調整#fluidimage的大小)注意:調整大小部分有效。 僅viewportwidth檢測和if / else語句尚不起作用。
$(window).load ( function () {
function resizer (index, measurement) {
var imageresize = 80;
var viewportWidth = width();
if ((viewportWidth >= 1680)) {
imageresize = 100;
} else if ((viewportWidth <= 1680) && (viewportWidth > 1280)) {
imageresize = 80;
} else if ((viewportWidth <= 1280) && (viewportWidth > 1024)) {
imageresize = 60;
} else if ((viewportWidth <= 1024) ) {
imageresize = 40;
} else {
imageresize = 100;
}
this.wCall = (typeof this.wCall == "null") ? true : this.wCall ^ true;
return this.wCall ? Math.round (measurement * imageresize / 100) : measurement;
}
$("#fluidimage").width (resizer).height (resizer);
} );
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.