轮换广告代码加演示[JavaScript实现]

2008-02-23 07:49:54来源:互联网 阅读 ()

新老客户大回馈,云服务器低至5折

  演示效果:http://www.webjx.com/htmldata/2005-11-26/test.html

<script LANGUAGE="javascript">
<!--
var cpAD=new Array();
var cpADlink=new Array();
var cpADmsg=new Array();
//定义了5个数组
var adNum=5;
var coll=0;

//ad/1.html 那时你链接的广告地址

cpAD[0]="banners/mba.gif";
cpADlink[0]="ad/1.html";
cpADmsg[0]="1";

cpAD[1]="banners/google.gif";
cpADlink[1]="ad/2.html"
cpADmsg[1]="2";

cpAD[2]="banners/2005.gif";
cpADlink[2]="ad/3.html";
cpADmsg[2]="3";

cpAD[3]="banners/cz8y.gif";
cpADlink[3]="ad/4.html";
cpADmsg[3]="4";

cpAD[4]="banners/JG_YUEDU.gif";
cpADlink[4]="ad/5.html";
cpADmsg[4]="5";

var preloadedimages=new Array();
for (i=1;i<cpAD.length;i ){
preloadedimages[i]=new Image();
preloadedimages[i].src=cpAD[i];
}

//跳转的URL地址
function jump2url()
{
jumpUrl=cpADlink[adNum];
jumpTarget='_blank';
if (jumpUrl != '')
{
if (jumpTarget != '')
window.open(jumpUrl,jumpTarget);
else location.href=jumpUrl;
}
}

//图片变化的函数
function changeimg(n)
{
adNum=n;
switch(adNum)
{
case 0:
{
window.img1.src="banners/1-2.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5.gif";
break;
}
case 1:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2-2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5.gif";
break;
}
case 2:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3-2.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5.gif";
break;
}
case 3:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4-2.gif";
window.img5.src="banners/5.gif";
break;
}
case 4:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5-2.gif";
break;
}
}
window.clearInterval(theTimer);
adNum=adNum-1;
nextAd();
}
//当点击时直接跳转
function nextAd(){
coll ;
if(coll>1)
{
switch(adNum 1)
{
case 5:
{
window.img1.src="banners/1-2.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5.gif";
break;
}
case 1:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2-2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5.gif";
break;
}
case 2:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3-2.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5.gif";
break;
}
case 3:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4-2.gif";
window.img5.src="banners/5.gif";
break;
}
case 4:
{
window.img1.src="banners/1.gif";
window.img2.src="banners/2.gif";
window.img3.src="banners/3.gif";
window.img4.src="banners/4.gif";
window.img5.src="banners/5-2.gif";
break;
}
}
}
if(adNum<cpAD.length-1)adNum ;
else adNum=0;
setTransition();
document.images.cpADrush.src=cpAD[adNum];
playTransition();
displayStatusMsg();
//定义了轮换时间 5s
theTimer=setTimeout("nextAd()", 5000);
}

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:关于多个checkbox默认选中问题

下一篇:关于网页源代码屏蔽