实现图片轮播的效果 1 <script language =javascript > 2 function $(id){ 3 return document.getElementById(id); 4 } 5 var curIndex = 0; 6 //时间间隔 单位毫秒 7 var times = 1000; 8 var arr = []; 9 arr[0] = "0.jpg"; 10 arr[1] = "1.jpg"; 11 arr[2] = "2.jpg"; 12 arr[3] = "3.jpg"; 13 arr[4] = "4.jpg"; 14 arr[5] = "5.jpg"; 15 arr[6] = "6.jpg"; 16 setInterval(function(){ 17 var obj = $("obj"); 18 if (curIndex==arr.length-1) 19 { 20 curIndex=0; 21 } 22 else 23 { 24 curIndex+=1; 25 } 26 obj.src = arr[curIndex]; 27 } ,times); 28 </script> 29 <img id=obj src ="0.jpg"/>
时间: 2024-12-22 05:59:33