爱东东

VS.NET,IT,个人,个人网站 爱东东 http://www.idongdong.net

 

自己写的对联JS代码

function CCouplet(pDivName,pImgUrl,pWidth,pHeigth,pInterval,pActionUrl,pAction,pIsClickAction,pIsLeft,pXOffset,pYOffset){
 this.DivName=pDivName;
 this.ImgUrl=pImgUrl.toLowerCase();
 this.Width=pWidth;
 this.Heigth=pHeigth;
 this.Interval=pInterval;
 this.Action=pAction;
 this.ActionUrl=pActionUrl;
 this.IsClickAction=pIsClickAction;
 this.IsLeft=pIsLeft;
 this.XOffset=pXOffset;
 this.YOffset=pYOffset;
 var othis=this;
 var x=0,y=0;
 if(this.IsLeft==true){
  x=this.XOffset;
 }else{
  x=document.body.scrollWidth - this.XOffset - this.Width;
 }
 y=this.YOffset;
 var timehandler;
 var imgurlsrc=this.ImgUrl;
 if(imgurlsrc.substring(imgurlsrc.length - 4)==".swf"){
  if(this.IsClickAction==true){
   document.getElementById(this.DivName).innerHTML="<a href=\""+this.ActionUrl+"\" onclick=\""+this.Action+"\" target=_blank><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\""+this.Width+"\" height=\""+this.Heigth+"\"> <param name=movie value=\""+this.ImgUrl+"\"> <param name=quality value=high> <param name=\"wmode\" value=\"transparent\"></object></a>";
  }else{
   document.getElementById(this.DivName).innerHTML="<a href=\""+this.ActionUrl+"\" target=_blank><object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\""+this.Width+"\" height=\""+this.Heigth+"\"> <param name=movie value=\""+this.ImgUrl+"\"> <param name=quality value=high> <param name=\"wmode\" value=\"transparent\"></object></a>";
  }
 }else{
  if(this.IsClickAction==true){
   document.getElementById(this.DivName).innerHTML="<a href=\""+this.ActionUrl+"\" onclick=\""+this.Action+"\" target=_blank><img src=\""+this.ImgUrl+"\" width="+this.Width+" height="+this.Heigth+"></img></a>";
  }else{
   document.getElementById(this.DivName).innerHTML="<a href=\""+this.ActionUrl+"\" target=_blank><img src=\""+this.ImgUrl+"\" width="+this.Width+" height="+this.Heigth+"></img></a>";
  }
 }
 this.Move=function(){
  y=document.body.scrollTop + this.YOffset;
  document.getElementById(this.DivName).style.zIndex=10;
  document.getElementById(this.DivName).style.position="absolute";
  document.getElementById(this.DivName).style.left=x;
  document.getElementById(this.DivName).style.top=y;
  document.getElementById(this.DivName).style.width=this.Width;
  document.getElementById(this.DivName).style.height=this.Heigth;
 }
 this.Start=function(){
  timehandler=window.setInterval(function(){othis.Move();},this.Interval);
 }
 this.Stop=function(){
  window.clearInterval(timehandler);
 }
 document.getElementById(this.DivName).onmouseover=function(){othis.Stop();};
 document.getElementById(this.DivName).onmouseout=function(){othis.Start();};
 if(this.IsClickAction==false){
  window.setTimeout(this.Action,1);
 }
 othis.Start();
}
---------------------------------------------
使用时只需要 var c=new CCouplet(pDivName,pImgUrl,pWidth,pHeigth,pInterval,pActionUrl,pAction,pIsClickAction,pIsLeft,pXOffset,pYOffset);即可
pDivName:=div名称,对联需要附着于一个div
pImgUrl:=对联对应的图片url,可以是图片也可以是swf
pWidth,pHeigth:=对联尺寸
pInterval:=对联移动处理时间间隔(毫秒),设为500好了
pActionUrl:=点击对联时的弹出的链接,可以为"",对于图片可以,对于swf需要swf自己处理了
pIsClickAction:=是否在点击对联时执行 pAction 中的代码(应该为js的function名称),true表示点击时执行,false,则为展现飘窗时执行
pAction:=点击飘窗时需要做的动作,对应js的function名称,可以为""
pIsLeft:=true表示做对联 false表示右对联
pXOffset:=对联距离左边界(pIsLeft=true)或者右边界(pIsLeft=false)的x轴相对距离(像素)
pYOffset:=对联距离浏览器顶部的y轴相对距离(像素)

posted on 2006-06-30 10:53  爱东东  阅读(802)  评论(0编辑  收藏  举报

导航