js随机效果之图片切换代码

发布时间:2020-04-10编辑:脚本学堂
为大家介绍一个js实现的随机图片切换的代码,有需要的朋友,可以参考下。

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD html 4.0 Transitional//EN">
<html>
<head>
<title>随机图片切换_www.jb200.com</title>
<meta http-equiv=Content-Type content="text/html; charset=gb2312">
<SCRIPT language=javascript>
<!-- // BannerAD
var bannerAD=new Array();
var bannerADlink=new Array();
var adNum=0;
bannerAD[0]="img/0.jpg";//图片路径名称
bannerADlink[0]="http://www.jb200.com/ProductShow.asp?T_P_ID=117"; //图片链接地址
bannerAD[1]="img/1.jpg";
bannerADlink[1]="http://www.jb200.com/ProductShow.asp?T_P_ID=84";
bannerAD[2]="img/2.jpg";
bannerADlink[2]="http://www.jb200.com/ProductShow.asp?T_P_ID=85";
bannerAD[3]="img/3.jpg";
bannerADlink[3]="http://www.jb200.com/ProductShow.asp?T_P_ID=90";
bannerAD[4]="img/4.jpg";
bannerADlink[4]="http://www.jb200.com/ProductShow.asp?T_P_ID=93";
var preloadedimages=new Array();
for (i=1;i<bannerAD.length;i++){
preloadedimages[i]=new Image();
preloadedimages[i].src=bannerAD[i];
}

function setTransition(){
if (document.all){
bannerADrotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);
bannerADrotator.filters.revealTrans.apply();
}
}

function playTransition(){
if (document.all)
bannerADrotator.filters.revealTrans.play()
}

function nextAd(){
if(adNum<bannerAD.length-1)adNum++ ;
else adNum=0;
setTransition();
document.images.bannerADrotator.src=bannerAD[adNum];
playTransition();
theTimer=setTimeout("nextAd()", 4000);
}

function jump2url(){
jumpUrl=bannerADlink[adNum];
jumpTarget='_blank';
if (jumpUrl != ''){
if (jumpTarget != '')window.open(jumpUrl,jumpTarget);
else location.href=jumpUrl;
}
}
function displayStatusMsg() {
status=bannerADlink[adNum];
document.returnValue = true;
}

//-->
</SCRIPT>

<style type=text/css>body {
MARGIN: 0px; BACKGROUND-COLOR: #FFFFFF}
</style>

<meta content="MShtml 6.00.3790.4470" name=GENERATOR><title>最新产品</title></HEAD>
<body><A onMouseOver="displayStatusMsg();return document.returnValue"
href="javascript:jump2url()"><IMG
style="FILTER: revealTrans(duration=2,transition=20)" height=400
src="img/0.jpg" width=500 border=0 name=bannerADrotator></A>//图片初始化大小
<SCRIPT language=JavaScript>nextAd()</SCRIPT>
</body>
</html>