當前位置:編程學習大全網 - 網站源碼 - HTML圖片自動切換的代碼

HTML圖片自動切換的代碼

<script language =javascript > var curIndex=0; //時間間隔(單位毫秒),每秒鐘顯示壹張,數組***有5張圖片放在Photos文件夾下。 var timeInterval=1000; var arr=new Array(); arr[0]="photos/1.jpg"; arr[1]="photos/2.jpg"; arr[2]="photos/3.jpg"; arr[3]="photos/4.jpg"; arr[4]="photos/5.jpg"; setInterval(changeImg,timeInterval); function changeImg() { var obj=document.getElementById("obj"); if (curIndex==arr.length-1) { curIndex=0; } else { curIndex+=1; } obj.src=arr[curIndex]; } </script> <img id=obj src ="photos/1.jpg" width=200 height=150 border =0> 可以自己配置,自己設置每張圖片切換的時間間隔,自己設置每張圖片的路徑(絕對、相對路徑都可以)雖然很簡單,但是很實用。 ------------------------------------------------------------- 第二種方法: //修改圖片的寬度、高度,註意要和下面的壹樣,修改顯示位置 <style type="text/css"> #img1 {position:absolute; width:140px; height:105px; left:220px; top:125px; z-index:1; visibility:hidden;} #img2 {position:absolute; width:140px; height:105px; left:220px; top:125px; z-index:2} </style> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin var ie5=(document.getElementById && document.all); var ns6=(document.getElementById && !document.all);

  • 上一篇:免費軟件對比軟件大全
  • 下一篇:想做壹個工資查詢系統,但是不知道怎麽下手,希望高手指點指點,謝謝了。
  • copyright 2024編程學習大全網