備忘(圖片的等比例縮放)
<PRE style="BACKGROUND-COLOR: #c5c5c5; FONT-WEIGHT: bold" class=javascript name="code">function resizeimg(ImgD,iwidth,iheight) { var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0){ if(image.width/image.height>= iwidth/iheight){ if(image.width>iwidth){ ImgD.width=iwidth; ImgD.height=(image.heightiwidth)/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.widthiheight)/image.height; }else{ ImgD.width=image.width; ImgD.height=image.height; } ImgD.alt=image.width+"×"+image.height; } ImgD.style.cursor= "pointer"; //改變鼠標指針 ImgD.onclick = function() { window.open(this.src);} //點擊打開大圖片 if (navigator.userAgent.toLowerCase().indexOf("ie") > -1) { //判斷瀏覽器,如果是IE ImgD.title = "請使用鼠標滾輪縮放圖片,點擊圖片可在新窗口打開"; ImgD.onmousewheel = function img_zoom() //滾輪縮放 { var zoom = parseInt(this.style.zoom, 10) || 100; zoom += event.wheelDelta / 12; if (zoom> 0) this.style.zoom = zoom + "%"; return false; } } else { //如果不是IE ImgD.title = "點擊圖片可在新窗口打開"; } } }</PRE>
<img src="圖片url" onload="javascript:resizeimg(this,500,600);" />網上抄來的東西,寫上以免留在電腦中忘記了存放的地方(只支持ie內核的瀏覽器)