我用javascript写了个自动调整图片大小的函数,但运行时总有些图片没自动变,
来源:百度知道 编辑:UC知道 时间:2024/06/04 05:41:08
每次运行的情况都不同,我用的是同一张图试的?
//函数代码
function AutoImgSize(thisImg, scaleWidth,scaleHeight)
{
var imgWidth=thisImg.width;
var imgHeight=thisImg.height;
var WH=imgWidth/imgHeight;
if(imgWidth>imgHeight)
{thisImg.width=scaleWidth;thisImg.height=scaleWidth/WH;}
else
{thisImg.height=scaleHeight;thisImg.width=scaleHeight*WH;}
if(thisImg.width==0 || thisImg.height==0){thisImg.width=scaleWidth; thisImg.height=scaleHeight;}
}
//调用函数
out.println("<img src="+paddress+" onload=AutoImgSize(this,135,135) />");
//函数代码
function AutoImgSize(thisImg, scaleWidth,scaleHeight)
{
var imgWidth=thisImg.width;
var imgHeight=thisImg.height;
var WH=imgWidth/imgHeight;
if(imgWidth>imgHeight)
{thisImg.width=scaleWidth;thisImg.height=scaleWidth/WH;}
else
{thisImg.height=scaleHeight;thisImg.width=scaleHeight*WH;}
if(thisImg.width==0 || thisImg.height==0){thisImg.width=scaleWidth; thisImg.height=scaleHeight;}
}
//调用函数
out.println("<img src="+paddress+" onload=AutoImgSize(this,135,135) />");
我估计是转化时出错的,可能自动转化为float型拉,你用alter()看一下就明白拉,查看每次计算时得到的结果,我建议你把所有的结果扩大1000倍,等算好了之后再缩小1000倍就ok拉!试一下,肯定是计算时出现错误的.
我用javascript写了个自动调整图片大小的函数,但运行时总有些图片没自动变,
ASP 我用javaSCRIPT写了一个页,如何在VBSCRIPT中调用
第一次用javascript,哪里写错了呢????
为什么我用Dreamweaver编辑了一个网页其中有个Javascript的弹出菜单,为什么上传后就弹不出菜单了?
谁能帮我写一小段JAVASCRIPT代码?
我用javascript 写了一个这么简单的函数怎么就不好使呢?我就那了闷了
用javascript写一个简单的程序
求一段用javascript写的验证
关于用javascript写asp的问题.....
写个javascript,怎样点击 退出登录,就在 本页 把session值清空了啊?(jsp页面)