posts - 261,  comments - 564,  trackbacks - 8

随笔分类

文章分类

相册

收藏夹

Weblogs

搜索

  •  

最新评论

/*重新写了一下这个类,把原来几个函数都移了进去,并且加一个setEffect用来设置滤镜和效果!这样就可以从外部编写函数来增强效果了!并且不用再把对象名传递给类了!保留了对原来的兼容,对外只增加一个setEffect,当然还有play和stop。
演示地址:http://impx.net/scripts/tbanner.htm
*/

/*=============================
 Copyright by dragonimp
 All rights reserved.
 
  Description:class for TBanner
 
  version0.1 2004.8.26  first thought to make a class for banner
  version1.0 2004.11.24 simple function to support a banner
  version1.1 2004.12.10 basic effect in class
  version1.2 2005.2.6   setEffect to add other filters and effects
 
  Email:dragonimp@impx.net
  HomePage:http://www.impx.net
==============================
//Usage:(4 steps to run a banner)
 0. First of all, you should include this file in your source.
  1. new TBanner to initialize a new TBanner object
 2. init the base path of images, names of images, and urls for links. first as default;
  3. setEffect to play unique effection. If omitted, it will play with default effection.
 4. start with interval time.

 //example:
 var banner_example=new TBanner();
 banner_example.init("/images/rotate/",new Array("r1.gif","r2.gif","r3.gif"),new Array("url1","url2","url3"));
 //banner_example.setEffect("progid:DXImageTransform.Microsoft.GradientWipe(duration=1.5,gradientSize=0.75,motion=forward)",null)
 //banner_example.setEffect("revealTrans(Duration=2.0,Transition=1)",function(obj){obj.filters[0].Transition = Math.floor(Math.random() * 23);})
 banner_example.start(5000);//millisecond
 
==============================*/


function TBanner()
{
 //create a contianer
 //==================================== 
 this.container=document.createElement("div");
 //document.body.appendChild(this.banner); this cannot work at unstandard env.
 var contianerID="TBannerContainer_"+this.container.uniqueID;
 document.write("<div id='"+contianerID+"'></div>");
 delete this.container;
 this.container=eval(contianerID);
   
 this.image=window.document.createElement("img");
 this.link=window.document.createElement("a");
 
 this.container.appendChild(this.link);
 this.link.appendChild(this.image); 
 //====================================
 
 this.id="banner_"+this.container.uniqueID;
 eval(this.id+"=this");//set the REAL bannerid as this object

 this.container.style.filter="revealTrans(Duration=2.0,Transition=1)";
 this.container.margin=0;
 this.container.padding=0;
 
 this.image.border=0;
 this.image.style.filter=this.container.style.filter;
 this.image.alt=this.id;
 
 this.link.target="_blank"; 
 
 this.index=0;
 this.delaytime=5000;
 this.timer=null;


 //public:

 this.init = function(basepath,images,urls)
 {
  this.imagebasepath=basepath;
  this.images=images;
  this.urls=urls;
  this.PreloadImages(images);
     
  this.switchBanner();//show first banner
 }
 
 this.start = function(delaytime)
 { 
  this.delaytime=(delaytime==null)?this.delaytime:delaytime;
  this.timer=setInterval(this.id+".play()",this.delaytime);
 }
 
 this.stop = function()
 {
  window.clearTimeout(this.timer);
  this.timer=null;
 }
 
 this.setEffect = function(filter,fnSwitch)
 {
  this.container.style.filter=filter;
  this.image.style.filter=filter;
  this.switchEffect=(fnSwitch==null)?function(){}:fnSwitch;
 }
  
 //switch to next banner and play effection
 this.play = function()
 {
  obj=this.image;//this.container doesn't work, why???
  //obj.style.visibility="hidden";
  obj.filters[0].Apply();
  this.switchBanner();
  obj.style.visibility="visible";
  obj.filters[0].Play();  
  
  this.switchEffect(obj);
 };
 
 
 //private:
 
 //default Effect Action
 this.switchEffect = function(obj)
 {
  obj.filters[0].Transition = Math.floor(Math.random() * 23);
 }
  
 //show next banner
 this.switchBanner = function()
 {
  var banner=this;
  if (banner.index<banner.urls.length)//change link
   banner.link.href=banner.urls[banner.index];
  else
  {
   if (banner.urls[0]!=null)
   {
    banner.link.href=banner.urls[0];
    banner.link.title=banner.link.href;
    banner.link.disabled=false;
    banner.link.target="_self";
   }
   else
   {
    banner.link.href="#";
    banner.link.target="_self";
    banner.link.disabled=true;
   }
  }
  banner.image.src=banner.imagebasepath+banner.images[banner.index];

  banner.index++;
  if(banner.index >= banner.images.length)banner.index=0;
 } 

 //Load images before play
 this.PreloadImages = function(images)
 {
  var preloadedimages=new Array()
  for (i=0;i<images.length;i++)
  {
   preloadedimages[i]=new Image()
   preloadedimages[i].src=images[i];
  }
  delete preloadedimages;
 }
}

posted on 2005-02-12 23:28 dragonimp 阅读(2522) 评论(1)  编辑 收藏
标题  
姓名  
主页
内容   
请输入验证码:
*
  登录  使用高级评论  Top 订阅回复  取消订阅
[使用Ctrl+Enter键可以直接提交]