把圖片的鏈接輸入到數(shù)據(jù)庫里,如 images/abc.jpg
顯示時(shí)用 <img src="<%=rs("img")%>">。
但要怎樣控制每一張圖片的大小呢?如果加上width=60 height=30的話,每一張圖片就會(huì)一樣大小。
但要它根據(jù)原來的size放大縮小,請(qǐng)問要怎樣寫?
function DrawImage(ImgD,twidth,theight){
var flag=false;
var image=new Image();
var iwidth = twidth; //定義允許圖片寬度
var iheight = theight; //定義允許圖片高度
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= iwidth/iheight){
if(image.width>iwidth){
ImgD.width=iwidth;
ImgD.height=(image.height*iwidth)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
else{
if(image.height>iheight){
ImgD.height=iheight;
ImgD.width=(image.width*iheight)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
ImgD.alt=image.width+"×"+image.height;
}
}
}
<img src="="<%=rs("img")%>" onload="DrawImage(this,60,30)">
該文章在 2011/2/26 18:26:56 編輯過