TBanner in JScript

类别:网站制作 点击:0 评论:0 推荐:

做一个简单的Banner脚本相信网上看到的很多,但是很多其实并不好用,也不能满足要求.开始的时候随便写了一下,但是后来发现如果一个页面要放几个Banner,那就不好弄了.所以,就把整个写成一个class,这样子一个页面同时几个Banner都没有关系了.而且这样调用简单,而且又灵活.不管从哪方面来说,都是比较好的.banner效果:http://impx.net/scripts/tbanner.htm
希望这个功能对大家有帮助.

example: http://impx.net/scripts/tbanner.htm

/*=============================
 Copyright by dragonimp
 All rights reserved.
 
  Description:class for Banners
 
  version0.1 2004.8.26
  version1.0 2004.11.24
 
  Email:[email protected]
  HomePage:http://www.impx.net
==============================
//Usage:

 //new Banner with string "banner_example" which should be the same as var. name banner_example
 //init the base path of images, names of images, and urls for links
 //start with interval time

 var banner_example=new TBanner("banner_example");
 banner_example.init("/images/rotate/",new Array("r1.gif","r2.gif","r3.gif"),new Array("url1","url2","url3"));
 banner_example.start(5000);
 
==============================*/


//preload
function PreloadImages(images){
 var preloadedimages=new Array()
 for (p=0;p<images.length;p++){
 preloadedimages[p]=new Image()
 preloadedimages[p].src=images[p];
 }
}

function Transbanner(the_image,new_image){
 //var the_image=this.image;
 //var images=this.images; 
 the_image.src=new_image;
 the_image.style.visibility="hidden";
 the_image.filters.item(0).Apply();
 the_image.filters.item(0).Transition = Math.floor(Math.random() * 23);
 the_image.filters.item(0).Play(2.0);
 the_image.style.visibility="inherit";
}

function TBanner(bannerid){
 this.imagepath="";
 this.index=0;
 this.image=new Image();
 this.link=null;
 this.transtime=6000;
 this.bannerid=bannerid;
 this.images=new Array();
 this.urls=new Array();
 this.init=BannerInit;
 this.start=BannerStart;
 this.trans=BannerTrans;
}

function BannerInit(imagepath,images,urls){
 this.imagepath=imagepath;
 this.images=images;
 this.urls=urls;
 var banner_image=this.bannerid+"_image";
 var banner_link=this.bannerid+"_link";
 document.write("<a id='"+banner_link+"' target=_blank><IMG id='"+banner_image+"' border=0 style='FILTER:revealTrans(Duration=3.0,Transition=1);VISIBILITY: hidden'></a>")
 PreloadImages(images);
 this.image=eval(banner_image);
 this.link=eval(banner_link);
 BannerTrans(this);//start first trans
}

function BannerTrans(banner){
 Transbanner(banner.image,banner.imagepath+banner.images[banner.index]);
 
 if (banner.index<banner.urls.length)
  banner.link.href=banner.urls[banner.index];
 else{ 
  banner.link.href='#';
  banner.link.target='_self';
  banner.link.disabled=true;
 }
  
 banner.index++;
 if (banner.index >= banner.images.length)
  banner.index=0;
}

function BannerStart(transtime){ 
 this.transtime=transtime;
 setInterval("BannerTrans("+this.bannerid+")",this.transtime)
}

本文地址:http://com.8s8s.com/it/it31031.htm