前後輪翻的JavaScript圖片切換特效

來源:互聯網
上載者:User

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="gb2312">
<head>
<title>前後輪翻的JavaScript圖片切換</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<style type="text/css">
* { margin:0; padding:0; }
body {
 margin:0;
 color:#88c; background:#333;
}
img { margin:0; padding:0; border:0; }
#js_F {
 position:relative;
 top:10px; left:10px;
 overflow:hidden;
 width:270px; height:185px;
 background:#33c;
}
#js_F img{
 position:absolute;
 top:0; left:0;
 width:270px; height:185px;
}
</style>
</head>
<body>
<div id="js_F"></div>
<script type="text/javascript">
<!--///*--><![CDATA[/*><!--*/
var js_F = document.getElementById("js_F");
var imgList = ["/jscss/demoimg/wall1.jpg", "/jscss/demoimg/wall2.jpg", "/jscss/demoimg/wall3.jpg", "/jscss/demoimg/wall4.jpg", ];
var imgTemp = new Array();
for (i=0; i<imgList.length; i++){
 imgTemp[i] = new Image();
 imgTemp[i].src = imgList[i];
}
var imgs = new Array();
var imgID = 0, nextImgID, proveImgID;
var tf = true; //圖片移動方向標誌
var speed1 = 10; speed2 = 3100; //速度
function imgInit(){
 var content = '';
 for (i=0; i<imgList.length; i++){
  content += '<img src="' + imgList[i] + '" style="left:0;" />\n';
 }
 js_F.innerHTML = content;
 imgs = js_F.getElementsByTagName('img');
 imgs[0].style.zIndex = 20;
 imgs[1].style.zIndex = 15;
}
function imgChange(){
 if ((imgID+1)<imgList.length){
  nextImgID = imgID + 1;
 } else if (imgID<imgList.length) {
  nextImgID = 0;
 } else {
  imgID = 0;
  nextImgID = imgID + 1;
 }
 imgs[imgID].style.zIndex = 20;
 imgs[nextImgID].style.zIndex = 15;
 setTimeout('imgShow()',speed2);
}
function imgShow(){
 if (tf){ //imgID向左邊移動2/3,nextImgID向右邊1/3
  if (parseInt(imgs[imgID].style.left)>-180){
   imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)-10) + 'px';
   imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)+5) + 'px';
   setTimeout('imgShow()',speed1);
  } else {
   tf = !tf;
   imgs[imgID].style.zIndex = 15;
   imgs[nextImgID].style.zIndex = 20;
   setTimeout('imgShow()',speed1);
  }
 } else {
  if (parseInt(imgs[imgID].style.left)<0){
   imgs[imgID].style.left = (parseInt(imgs[imgID].style.left)+10) + 'px';
   imgs[nextImgID].style.left = (parseInt(imgs[nextImgID].style.left)-5) + 'px';
   setTimeout('imgShow()',speed1);
  } else {
   imgs[imgID].style.zIndex = 10;
   tf = !tf;
   imgID++;
   imgChange();
  }
 }
}
imgInit();
imgChange();
/*]]>*///-->
</script>
</body>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.