明辉站/网站教程/内容

暑期缤纷巨献之~------按比例改变你的图象

网站教程2024-01-14 阅读
[摘要]//-------------------------- ROOT1.嘿嘿!//--------------------------var imgs,timesfunction showimg(a) //a代表你要传入的图片地址imgs=new Image();imgs.src=a...

//--------------------------
         ROOT1.嘿嘿!
//--------------------------
var imgs,times
function showimg(a) //a代表你要传入的图片地址
{
imgs=new Image();
imgs.src=a
times=setTimeout("se()",700)
}
function se(){
if(imgs.complete==true){
clearTimeout(times);
loads();
}
}

function loads()  
//这里限制了图片必须按比例缩小到不能宽过190,不能高过120
{
var zhen=false;
var picW=imgs.width;
var picH=imgs.height;
var picws=picW
var pichs=picH
if (picW>190){
picws=190;
pichs=parseInt(picH*(190/picW));
if(pichs>120){
pichs=120;
picws=parseInt(picW*(120/picH))
}
zhen=true
}else{
if (picH>120){
pichs=120;
picws=parseInt(picW*(120/picH));
zhen=true
}
}
var str;
if(zhen){
str="<a href=\"javascript:winopen('"+imgs.src+"',"+picW+","+picH+")\">"+
    "<img src=\"" + imgs.src + "\" border=\"0\" width=\"" +picws+"\" height=\""+pichs+"\"></a>"
}else{
str="<img src=\"" + imgs.src + "\" border=\"0\" width=\"" +picws+"\" height=\""+pichs+"\">"
}
document.all["imgdiv"].innerHTML=str
                //这里是将图片写到一个TD,你也可以改成层的.
delete(imgs);
}

function winopen(url,wid,hei){
window.open(url,"","width="+(wid+10)+",height="+(hei+10))
}

……

相关阅读