又一個圖片自動縮小的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里改,這里也作相應的改.
相關文章
js實現(xiàn)圖片加載時候逐漸出現(xiàn)的雜色效果
有一些網(wǎng)站在加載圖片的時候不是一下子就出來了,而是由模糊到清淅,或是由一種不占用過多網(wǎng)絡資源的方式先大致顯示,然后再慢慢加載,避免因用戶等不及將網(wǎng)頁關掉,像馬賽克效果、沙子效果等2010-08-08javascript實現(xiàn)的三維正方體(兼容ie7,ff)
2008-02-02推薦自用 Javascript 縮圖函數(shù) (onDOMLoaded)……
推薦自用 Javascript 縮圖函數(shù) (onDOMLoaded)……...2007-10-10