又一個圖片自動縮小的JS代碼
更新時間:2007年03月10日 00:00:00 作者:
<script language="JavaScript">
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 180/110){
if(image.width>180){
ImgD.width=180;
ImgD.height=(image.height*110)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt="bigpic" */
}
else{
if(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt="bigpic" */
}
}
}
//-->
</script>
圖片使用的地方:
<img src="圖片" border=0 width="180" height="110" onload="JavaScriptrawImage(this);">
width="180" height="110" 注意這里最好限定,如果不限定加載圖時會成原大,然后再縮小,這個過程如果圖大了很難看的.這里是寬度和高度,在前面的JS里改,這里也作相應的改.
<!--
var flag=false;
function DrawImage(ImgD){
var image=new Image();
image.src=ImgD.src;
if(image.width>0 && image.height>0){
flag=true;
if(image.width/image.height>= 180/110){
if(image.width>180){
ImgD.width=180;
ImgD.height=(image.height*110)/image.width;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt="bigpic" */
}
else{
if(image.height>110){
ImgD.height=110;
ImgD.width=(image.width*110)/image.height;
}else{
ImgD.width=image.width;
ImgD.height=image.height;
}
/*ImgD.alt="bigpic" */
}
}
}
//-->
</script>
圖片使用的地方:
<img src="圖片" border=0 width="180" height="110" onload="JavaScriptrawImage(this);">
width="180" height="110" 注意這里最好限定,如果不限定加載圖時會成原大,然后再縮小,這個過程如果圖大了很難看的.這里是寬度和高度,在前面的JS里改,這里也作相應的改.
相關文章
推薦自用 Javascript 縮圖函數 (onDOMLoaded)……
推薦自用 Javascript 縮圖函數 (onDOMLoaded)……...2007-10-10

