這個小DEMO,主要用box固定長寬用來顯示圖片,將圖片放入imagebox中,連接起來,每次換圖片則將imagebox的style屬性的margin-left改動,能形成輪播的效果。 複製程式碼 代碼如下: -/html/PUBL "IC DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 無標題文件 <BR>.box { <BR>width: 900px; <BR>height: 350px; <BR>margin: 20px; <BR>overflow: hidden; <BR>margin: 20px; <BR>overflow: hidden;; ; <BR>} <BR>.imagebox { <BR>width: 3600px; <BR>height: 350px; <BR>-webkit-transition: all 1s ease-in-out; <BR>-moz-transition: 1s ease-in-out; <BR>-o-transition: all 1s ease-in-out; <BR>transition: all 1s ease-in-out; <BR>} <BR>.imagebox img { <BR> width: 900px; <BR>float: left; <BR>height: 350px; <BR>} <BR> <BR>var int=setInterval("change()",3*1000); <BR>var a=document.getElementById("ImageBox"); <BR>var i=1; <BR>function change(){ <BR>if(i==4){ <BR>i=0; <BR>} <BR>i=i 1; <br>a .style.marginLeft=(1-i)*900 "px"; <br><BR>} <BR>function stopchange(){clearInterval(int);} <BR>function startchange(){int=setInterval(" change()",2*1000);} <BR>a.onmouseover=function(){clearInterval(int);} <BR>a.onmouseout=function() {int=setInterval("change()",2 *1000);} <BR>function turnleft(){ <BR>stopchange(); <BR>i=i 1; <BR>a.style.marginLeft=(1-i)*900 "px"; <BR>if(i==4){ <BR>i=0; <BR>} <BR>startchange(); <BR>} <BR>function turnright(){ <BR>stopchange(); <BR>if (i>1){ <BR>a.style.marginLeft=(2-i)*900 "px"; <BR>i=i-1; <BR>}else{ <BR>a.style.marginLeft= -3*900 "px"; <BR>i=4; <BR>} <BR>startchange(); <BR>} <BR>