天天看點

網頁裡控制圖檔大小的相關代碼

1、用滑鼠拖動來改變大小

<SCRIPT LANGUAGE="JavaScript">

function resizeImage(evt,obj){

newX=evt.x

newY=evt.y

obj.width=newX

obj.height=newY

}

</script>

<img src="7say.gif" οndrag="resizeImage(event,this)">

2、用滑鼠滾動控制圖檔大小

<img src="7say.gif" οnmοuseenter="focus();" οnmοuseοut="blur();" onmousewheel="width+=(window.event.wheelDelta==120)?-5:+5;">

3、圖檔标簽裡用代碼控制大小

<img src="[!--picurl--]" οnlοad="if(this.width>screen.width-500)this.style.width=screen.width-500;">

4、CSS控制圖檔大小

1. css2直接實作: img{max-width: 500px;} (IE暫不支援)

2. expression實作: img{width:expression(width>500?"500px":width);} (IE only)

3. 使用js. 方法: 用 document.getElementsByTagName("IMG") 的方法取得全部img元素 周遊img元素 判斷其寬度并做相應操作

5、原圖(小圖):<br>

i(UiQ-U,],A0<IMG id="img1" src="http://www.google.com/options/icons/picasa.gif" style="border:1px #ff0000 solid" >PHPChina 開源社群門戶7xA1l Af3d

<a href=javascrīpt:void(0) ōnClick="alert( document.getElementById('img1').width + '×' + document.getElementById('img1').height ) ">圖檔大小</a>

!N(j9E4h1}.M5F0<br><hr><br>

b.^ OQA06、小圖放大:<br>

gV9K4v5l{(y @0<IMG id="img2" src="http://www.google.com/options/icons/picasa.gif" style="border:1px #ff0000 solid" ōnload="resizeImg(this)">

p4}'[email protected]<a href=javascrīpt:void(0) ōnClick="alert( document.getElementById('img2').width + '×' + document.getElementById('img2').height ) ">圖檔大小</a>PHPChina 開源社群門戶R'? ^{H6Il%j/U

<br><hr><br>PHPChina 開源社群門戶w e m;qbIx'MV

7、原圖(大圖):<br>

*UL/dF6U0<IMG id="img3" src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" style="border:1px #ff0000 solid" >

:jX0_/fOS,Y�H^/[V6r0<a href=javascrīpt:void(0) ōnClick="alert( document.getElementById('img3').width + '×' + document.getElementById('img3').height ) ">圖檔大小</a>PHPChina 開源社群門戶*P'@*HU5hJ2uu

<br><hr><br>

&x /7]0dw08、大圖縮小:<br>

?L'Y$y }yQ;~0<IMG id="img4" src="http://www.google.cn/intl/zh-CN/images/logo_cn.gif" style="border:1px #ff0000 solid" ōnload="resizeImg(this)">PHPChina 開源社群門戶4z$u#c#f1T%W E x&_

<a href=javascrīpt:void(0) ōnClick="alert( document.getElementById('img4').width + '×' + document.getElementById('img4').height ) ">圖檔大小</a>PHPChina 開源社群門戶[B&J7ME |0n

<br><hr><br>PHPChina 開源社群門戶w*U$g/o1?:]%@

PHPChina 開源社群門戶8r$WPEA<scrīpt type="text/javascrīpt">

"d�d%Y.~3z/c#bE o0function resizeImg(obj){

;L^[email protected] C^ s(H5j0   if(obj.width>100||obj.height>100){PHPChina 開源社群門戶%MCx?? V0z

      for(i=0;(obj.width>=101||obj.height>=101);i++)PHPChina 開源社群門戶jX%h#u t/$[

      {

&L(@g)k m;K0         obj.width-=1;PHPChina 開源社群門戶1S I:Ud*^6_y

      }PHPChina 開源社群門戶[email protected])dvqic

   }PHPChina 開源社群門戶Ge,uJ./*g4NSA.`6|7w

   else if(obj.width<100||obj.height<100){

OT(`j"P8c0      for(i=0;(obj.width<=99&&obj.height<=99);i++){

R:}hHJ~S0         obj.width+=1;PHPChina 開源社群門戶4},QDn @DW

      }PHPChina 開源社群門戶$Q7{ v#C}X

   }PHPChina 開源社群門戶1~/ s{`Td*e(H"x

}PHPChina 開源社群門戶5s0F.Lq["o

</scrīpt>

繼續閱讀