转至繁体中文版     | 网站首页 | 图文教程 | 资源下载 | 站长博客 | 图片素材 | 武汉seo | 武汉网站优化 | 
最新公告:     敏韬网|教学资源学习资料永久免费分享站!  [mintao  2008年9月2日]        
您现在的位置: 学习笔记 >> 图文教程 >> 站长学院 >> Web开发 >> 正文
飘浮广告的显示脚本类(VBS,JS双版)         ★★★★

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

作者:闵涛 文章来源:闵涛的学习笔记 点击数:1431 更新时间:2009/4/23 11:30:56
在写一个项目时要用到广告模块,为了不想用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&"'" 
If ImageHeight=0 Or Not IsNumeric(ImageHeight) Then 
ImageHeight=80 
End If 
ImageHeight=" height='"&ImageHeight&"'" 
document.write "<div id=""img"&DivID&""" style=""position:absolute;"">" 
document.write "<a href="""&adHref&""" target=""_blank"" title='"&adTitle&"'>" 
document.write "<object codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0'"&ImageWidth&ImageHeight&" align='middle'>" 
document.write "<param name='movie' value='"&ImgSrc&"'>" 
document.write "<param name='quality' value='high'>" 
document.write "<embed src='"&ImgSrc&"'"&ImageWidth&ImageHeight&" quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash'></embed></object>" 
document.write "</a></div>" 
End Sub 
End Class 


[JS脚本]
以下是代码片段:
file://*****************漂浮广告显示类**************************************************** 
file://* 作者:死在水中的鱼 
file://* 脚本语言:Javascript 
file://* 用法: 
file://* var adver=new adverClass 
file://* adver.setObjName("adver"); file://这句不能setTime所以没有用 
file://* adver.setDivID(1); file://这句可以不用 
file://* adver.setImageType(1); file://设为0时或不写这句时则是普通图片,1则为Flash动画文件 
file://* adver.setImagePX(299,87); file://设置图片的宽度与高度 
file://* adver.showAdver("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/","这是什么"); 
file://* var adver1=new adverClass(); 
file://* adver1.showAdver("img.gif","http://www.chinese.bj.cn/","这是什么"); 
file://* setTimer(); 
file://* file://因为类里不能写setTime所以只好拿出来写-_-##(VBS脚本竟然可以。我倒) 
file://* function setTimer(){ 
file://* adver.floatScroll(); 
file://* adver1.floatScroll(); 
file://* setTimeout("setTimer()",80); 
file://* } 
file://*********************************************************************************** 
function adverClass(){ 
var objName=""; 
var imageType=0; 
var imageWidth=imageHeight=0; 
var iTop=iLeft=0; 
var topFlag=leftFlag=false; 
var divID=0,objDiv=null; 
var offWidth=offHeight=0; 
var width=document.body.clientWidth; 
var height=document.body.clientHeight; 
var delay=30; file://时间的延迟值 
var topStep=2,leftStep=3; file://一步跨多少 
var inter; 
file://此处是当外部不设置divID的值能够确保层的ID是唯一 
divID=Math.round(Math.random()*100000) 
file://广告的类型 0=普通图片 1=Flash广告图片 
this.setImageType=function(sType){ 
if(sType!=1&&sType!=0){sType=0;} 
imageType=sType; 

file://外部调用的变量名 
this.setObjName=function(sName){objName=sName;} 
file://广告图片的高度与宽度 
this.setImagePX=function(iWidth,iHeight){ 
if(!isNaN(iWidth)){ 
imageWidth=iWidth; 
}else{ 
imageWidth=0; 

if(!isNaN(iHeight)){ 
imageHeight=iHeight; 
}else{ 
imageHeight=0; 


file://设置广告所在层的ID值 
this.setDivID=function(iDiv){divID=iDiv;} 

file://主函数,显示广告代码 
this.showAdver=function(adImgSrc,adHref,adTitle){ 
if(imageType==0){ 
showImageHtml(adImgSrc,adHref,adTitle); 
}else{ 
showFlashHtml(adImgSrc,adHref,adTitle); 

eval("objDiv=document.all.img"+divID+";"); 
file://取得图片的宽度 
offWidth=objDiv.offsetWidth; 
offHeight=objDiv.offsetHeight; 
file://随机显示广告的开始位置 
iLeft=Math.round(Math.random()*(width-offWidth)); 
iTop=Math.round(Math.random()*(height-offHeight)); 
objDiv.style.pixelLeft=iLeft; 
objDiv.style.pixelTop=iTop; 
file://定时开始 
file://startTimer(); 

file://主函数,漂浮游动显示广告 
this.floatScroll=function(){ 
var iRnd; 
iRnd=Math.round(Math.random()*100); file://此值是为了能使多图显示时产生不同的轨迹 
if(objDiv==null)

[1] [2]  下一页


[VB.NET程序](原创)飘浮广告显示脚本类(VBS,JS双版)  [VB.NET程序]飘浮广告显示脚本类(VBS,JS双版)
[Web开发]飘浮广告显示脚本类(VBS,JS双版)  
教程录入:mintao    责任编辑:mintao 
  • 上一篇教程:

  • 下一篇教程:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      注:本站部分文章源于互联网,版权归原作者所有!如有侵权,请原作者与本站联系,本站将立即删除! 本站文章除特别注明外均可转载,但需注明出处! [MinTao学以致用网]
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    同类栏目
    · Web开发  · 网页制作
    · 平面设计  · 网站运营
    · 网站推广  · 搜索优化
    · 建站心得  · 站长故事
    · 互联动态
    更多内容
    热门推荐 更多内容
  • 没有教程
  • 赞助链接
    更多内容
    闵涛博文 更多关于武汉SEO的内容
    500 - 内部服务器错误。

    500 - 内部服务器错误。

    您查找的资源存在问题,因而无法显示。

    | 设为首页 |加入收藏 | 联系站长 | 友情链接 | 版权申明 | 广告服务
    MinTao学以致用网

    Copyright @ 2007-2012 敏韬网(敏而好学,文韬武略--MinTao.Net)(学习笔记) Inc All Rights Reserved.
    闵涛 投放广告、内容合作请Q我! E_mail:admin@mintao.net(欢迎提供学习资源)

    站长:MinTao ICP备案号:鄂ICP备11006601号-18

    闵涛站盟:医药大全-武穴网A打造BCD……
    咸宁网络警察报警平台