window.onload=function(){
ImgAuto(200,200);
}
ImgAuto(200,200);
}
解决方案 »
- 我不明白为什么第一行<div id="42" onclick="clicked(event)">1</div>可以嵌在script里,同时请帮忙补完程
- 有个小问题
- 高手帮忙看看这个CeEncodingFilter有什么问题?
- 获取div
- 如何所选单选框的值~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- xmlhttp能设置请求头的Referer字段吗
- 梅花雪写的代码看不懂,请大家指点!
- 这段代码出现的一些问题,求大家帮忙下。
- 关于MzTreeView的问题!请meizz回答一下!
- 请教一个字符串分割问题,急
- sohu的新邮箱界面的阅读邮件的浮动页面(或层)是怎么实现的
- 使用函数生成对象后,为什么无法调用。
function loadlargeimage(myimg,mywidth,myheight){
var tmp_img = new Image();
tmp_img.src=myimg.src;
image_x=tmp_img.width;
image_y=tmp_img.height;
if(image_x > mywidth){
tmp_img.height=image_y * mywidth / image_x;
tmp_img.width=mywidth;
if(tmp_img.height>myheight){
tmp_img.width=tmp_img.width * myheight / tmp_img.height;
tmp_img.height=myheight;
}
}else if(image_y > myheight)
{
tmp_img.width=image_x * myheight / image_y;
tmp_img.height=myheight;
if(tmp_img.width>mywidth){
tmp_img.height=tmp_img.height * mywidth / tmp_img.width;
tmp_img.width=mywidth;
}
}
myimg.width=tmp_img.width;
myimg.height=tmp_img.height;}
</script>
<img src="aaa.gif" onload="loadlargeimage(this,200,200)">
方法是:页面加载的图片先隐藏,在加载完后用ImgAuto(宽,高);例如:
<html>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>缩略图</title>
<script>
function ImgAuto(MaxWidth,MaxHeight)
{
for (i = 0; i < document.images.length; i++) {
var img=document.images[i];
var HeightWidth=img.offsetHeight/img.offsetWidth;
var WidthHeight=img.offsetWidth/img.offsetHeight;
if(img.readyState!="complete"){
return false;
}
if(img.offsetWidth>MaxWidth){
img.width=MaxWidth;
img.height=MaxWidth*HeightWidth;
}
if(img.offsetHeight>MaxHeight){
img.height=MaxHeight;
img.width=MaxHeight*WidthHeight;
}
}
}
function show_all(divId){
var img_f=document.getElmentById(divId);
img_f.style.display="block";
}
</script>
</head>
<body>
<div id="img_frame" style="display:none">
<img src="/../**.gif"/>
<img src="/../**.gif"/>
<img src="/../**.gif"/>
<img src="/../**.gif"/>
</div>
<script type="text/javascript>
ImgAuto(200,200);
show_all("img_frame");
</script>
</body>
</htm>