複製代碼 代碼如下: <BR>/* 判斷設備是否為PC */ <BR>function isPC() { <BR>var userAgentInfo = navigator.userAgent; <BR>var Agents = new Array(" Android", "iPhone", "SymbianOS","Windows Phone", "iPad", "iPod"); <BR>var flag = true; <BR>for ( var v = 0; v < Agents.length; v ) { <BR>if (userAgentInfo.indexOf(Agents[v]) > 0) { <BR>flag = false; <BR>break; <BR>} <BR>} <BR>return flag; <BR><br>/* 調整圖片大小*/ <br>function AutoResizeImage(maxWidth, maxHeight, objImg) { <BR>var img = new Image(); <BR>img.src = objImg.rc; >var hRatio; <BR>var wRatio; <BR>var Ratio = 1; <BR>var w = img.width; <BR>var h = img.height; <BR>wRatio = maxWidth / w; <BR> hRatio = maxHeight / h; <BR>if (maxWidth == 0 && maxHeight == 0) { <BR>Ratio = 1; <BR>} else if (maxWidth == 0) { // <BR>if (hRatio < 1) Ratio = hRatio; <BR>} else if (maxHeight == 0) { <BR>if (wRatio < 1) Ratio = wRatio; <BR>} else if (wRatio < 1 || hRatio; <BR>} else if (wRatio < 1 || hRatio < 1) { <BR>Ratio = (wRatio <= hRatio ? wRatio : hRatio); <BR>} <BR>if (Ratio < 1) { <BR>w = w * Ratio; <BR>h = h * Ratio; <BR>w = w * Ratio; <BR>h = h * Ratio; <BR>w = w * Ratio; <BR>h = h * Ratio; <BR>w = w * Ratio; <br>h = h * Ratio; <br>w = w * Ratio; <BR>h = h * Ratio; <BR>w = w * Ratio; <BR>h = h * Ratio; <BR>w = w * Ratio; <BR>h = h * Ratio; <BR>w = w * Ratio; <BR>h = h * Ratio; >} <BR>objImg.height = h; <BR>objImg.width = w; <BR>} <BR><BR>/* 設定不同裝置的縮放策略*/ <BR>function setImg(tagid,pcWidth,tagid,pcWidth,tagid,pcWidth(tagid,pcWidth,tagid,pcWidth(tagid,pcWidth,tagid,pcWidth(tagid,pcWidth,tagid,pcWidth(tagid,pcWidth,tagid,pcWidth(tagid,pcWidth,tagid,pc pcHeight,appWidth,appHeight){ <BR>var tag=document.getElementById(tagid); <BR>var images=tag.getElementsByTagName("img"); <BR>for(var i=0;i<images.length ;i ){ <BR>if(isPC){ <BR>AutoResizeImage(pcWidth, pcHeight, images[i]); <BR>}else{ <BR>AutoResizeImage(appWidth, appHeightse); >} <BR>} <BR>} <BR>window.onload=function(){ <BR>setImg('imgDIV',300,0,300,0); <BR>} <BR>