DW制作自动切换图js代码.docVIP

  • 34
  • 0
  • 约1.87千字
  • 约 2页
  • 2020-02-04 发布于江西
  • 举报
网页图片自动切换js代码 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); nPlus = 5?? //the % of fading for each step speed = 50 //速度 // You dont have to edit below this line nOpac = 100 function FadeImg(){ ??? if(document.getElementById){ ??????? document.getElementById(img1).style.visibility=visible; ??????? imgs = document.getElementById(img2); opacity = nOpac+nPlus; nOpac = opacity; setTimeout(FadeImg(),speed); ??? if(opacity100 || opacity0){ ??????? nPlus=-nPlus; ??? } ??? if(ie5){ ??????? imgs.style.filter=alpha(opacity=0); imgs.filters.alpha.opacity = opacity; ??? } ??? if(ns6){ ??????? imgs.style.MozOpacity = 0 + %; imgs.style.MozOpacity = opacity + %; ??? } } } onload=FadeImg; // End -- /script div id=img1 img src=photos\1.jpg border=0 width=140 height=105 /div div id=img2 img src=photos\2.jpg border=0 width=140 height=105 /div 网站

文档评论(0)

1亿VIP精品文档

相关文档