飘浮广告显示脚本类(VBS,JS双版)[1]

[入库:2005年8月18日] [更新:2007年3月24日]

本文简介:选择自 applebbs 的 blog

  在写一个项目时要用到广告模块,为了不想用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

本文关键:飘浮广告显示脚本类(VBS,JS双版)
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top