飄浮廣告顯示腳本類(VBS,JS雙版)
2024-07-21 02:15:32
供稿:網友
 
在寫一個項目時要用到廣告模塊,為了不想用asp生成腳本代碼時較麻煩,于是產生了寫腳本類的念頭,即是用一個類模塊的腳本代碼去控制所有在同一頁面顯示的漂浮廣告。但在寫的過程中發現js腳本竟然在settimeout里不能使用類的方法。奇怪,是不是我弄錯了還是js腳本就不能這樣??但vbs腳本就可以!我暈……
不說了,貼代碼:
[vbs腳本代碼]
以下是代碼片段:
'/****************漂浮廣告顯示類**************************************************** 
'/* 作者:死在水中的魚 
'/* 腳本語言:vbs 
'/* 用法: 
'/* set adver1=new adverclass 
'/* adver1.objname="adver1" '設置當前的對象名 [本身對象變量名] 
'/* adver1.imgtype=1 '圖片的類型 0=普通圖片 1=flash動畫 
'/* adver1.imagewidth=299 '圖片的寬度 
'/* adver1.imageheight=87 '圖片的高度 
'/* ####以下方法顯示廣告圖片(flash) 對象.printhtml "圖片地址","鏈接地址","提示信息" 
'/* adver1.printhtml "http://edu.qq.com/flash/moto-button.swf","http://www.chinese.bj.cn/' target="_blank" >http://edu.qq.com/flash/moto-button.swf","http://www.chinese.bj.cn/","這是什么" 
'/*********************************************************************************** 
class adverclass 
 public divid 
 public objname 
 private objdiv 
 public delay '改變數 
 public imgtype 
 private istep 
 private itop,ileft,width,height 
 private topflag,leftflag 
 '廣告圖片的大小 
 public imagewidth,imageheight 
 private sub class_initialize 
 randomize 
 divid=int(rnd(time)*9999+1) 
 delay=80 
 height=document.body.clientheight 
 width=document.body.clientwidth 
 itop=0 
 ileft=0 
 topflag=false:leftflag=false 
 istep=3 
 imgtype=0 '0 是圖片 1 是flash文件 
 imagewidth=0 
 imageheight=0 
 end sub 
 private sub class_terminate 
 end sub 
 public sub scrollimg() 
 dim offheight,offwidth,irnd 
 offwidth=objdiv.offsetwidth 
 offheight=objdiv.offsetheight 
 objdiv.style.left = ileft + document.body.scrollleft 
 objdiv.style.top = itop + document.body.scrolltop 
 irnd=int(rnd(time)*99+1) 
 if irnd>97 then topflag=not topflag 
 irnd=int(rnd(time)*9+1) 
 if irnd>98 then leftflag=not leftflag 
 if topflag then 
 itop=itop+istep*rnd(time) 
 else 
 itop=itop-istep*rnd(time) 
 end if 
 if leftflag then 
 ileft=ileft+istep*rnd(time) 
 else 
 ileft=ileft-istep*rnd(time) 
 end if 
 if itop<0 then 
 itop=0 
 topflag=true 
 elseif itop>height-offheight then 
 itop=height-offheight 
 topflag=false 
 end if 
 if ileft<0 then 
 ileft=0 
 leftflag=true 
 elseif ileft>width-offwidth then 
 ileft=width-offwidth 
 leftflag=false 
 end if 
 end sub 
 private sub start() 
 setinterval objname&".scrollimg()", delay 
 end sub 
 public sub printhtml(byval imgsrc,byval adhref,byval adtitle) 
 if imgtype=0 then 
 call printimagehtml(imgsrc,adhref,adtitle) 
 else 
 call printflashhtml(imgsrc,adhref,adtitle) 
 end if 
 execute "set objdiv=document.all.img"&divid 
 ileft=int(rnd(time)*(width-100)+1) 
 itop=int(rnd(time)*(height-100)+1) 
 objdiv.style.top=itop 
 objdiv.style.left=ileft 
 call start() 
 end sub 
 private sub printimagehtml(byval imgsrc,byval adhref,byval adtitle) 
 if imagewidth=0 or not isnumeric(imagewidth) then 
 imagewidth="" 
 else 
 imagewidth=" width='"&imagewidth&"'" 
 end if 
 if imageheight=0 or not isnumeric(imageheight) then 
 imageheight="" 
 else 
 imageheight=" height='"&imageheight&"'" 
 end if 
 document.write "<div id=""img"&divid&""" style=""position:absolute;"">" 
 document.write "<a href="""&adhref&""" target=""_blank"" title='"&adtitle&"'>" 
 document.write "<img src="""&imgsrc&""" alt="""&adtitle&""" border=""0"""&imagewidth&imageheight&"></a></div>" 
 end sub 
 private sub printflashhtml(byval imgsrc,byval adhref,byval adtitle) 
 if imagewidth=0 or not isnumeric(imagewidth) then 
 imagewidth=80 
 end if 
 imagewidth=" width='"&imagewidth&"'&q國內最大的酷站演示中心!