复制代码代码如下:
<html>
<头>
<脚本类型=“ text/javascript”>
/ *判断设备是否为pc */
函数ispc(){
var useragentinfo = navigator.useragent;
VAR Adgents = new Array(“ Android”,“ iPhone”,“ Symbianos”,“ Windows Phone”,“ iPad”,“ iPod”);
var flag = true;
for(var v = 0; v <adments.length; v ++){
if(useragentinfo.indexof(代理[v])> 0){
flag = false;
休息;
}
}
返回标志;
}
/ *调整图片大小 */
函数自动图像(maxWidth,maxheight,objimg){
var img = new Image();
img.src = objimg.src;
var hratio;
var Wratio;
var比率= 1;
var w = img.width;
var h = img.height;
wratio = maxWidth / w;
hratio = maxheight / h;
if(maxWidth == 0 && maxheight == 0){
比率= 1;
} else if(maxWidth == 0){//
if(hratio <1)比率= hratio;
} else if(maxheight == 0){
if(wratio <1)比率= wratio;
} else if(wratio <1 || hratio <1){
比率=(wratio <= hratio?wratio:hratio);
}
如果(比率<1){
w = w *比率;
h = h *比率;
}
objimg.height = h;
objimg.width = w;
}
/ *设置不同设备的缩放策略 */
函数setimg(tagid,pcwidth,pcheight,appwidth,appheight){
var tag = document.getElementById(tagid);
var images = tag.getElementsbytagname(“ img”);
for(var i = 0; i <images.length; i ++){
如果(ispc){
AutoresizeImage(PCWIDTH,PCHEIGHT,IMAGES [i]);
}别的{
AutoresizeImage(AppWidth,AppHeight,Images [i]);
}
}
}
window.onload = function(){
setimg('imgdiv',300,0,300,0);
}
</script>
</head>
<身体>
<div ID =“ imgdiv”>
<img src =“ http://192.168.1.116:9999/ffzx/news/20140205/015212022_1.jpg”/>
<div>
<img src =“ http://192.168.1.116:9999/ffzx/news/20140208/1386835169183.jpg”/>
</div>
</div>
<br>
</body>
</html>