js| Ads | scripts | show that when you write a project, you need to use the advertising module, in order to avoid using ASP to generate scripting code is more cumbersome, so the idea of writing script class, that is, using a class of script code to control all the floating ads displayed on the same page. But in the process of writing found that the JS script in the settimeout can not use the method of class. Strange, whether I was mistaken or JS script can not do this?? But the VBS script is OK! I faint ...
No, put the code:
[VBS script code] The following is a code fragment:
'/**************** floating ads display class ****************************************************
'/* Author: The fish that died in the water
'/* scripting language: VBS
'/* Usage:
'/* Set adver1=new Adverclass
'/* adver1.objname= ' Adver1 ' sets the current object name [itself object variable name]
'/* adver1.imgtype=1 ' picture of type 0 = normal picture 1=flash animation
The width of the '/* adver1.imagewidth=299 ' picture
The height of the '/* adver1.imageheight=87 ' picture
'/* ### #以下方法显示广告图片 (Flash) object. printhtml "Picture address", "link address", "Hint info"
' * * 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/"," What is this? "
'/***********************************************************************************
Class Adverclass
Public divID
Public objname
Private Objdiv
Public Delay ' Change number
Public Imgtype
Private Istep
Private Itop,ileft,width,height
Private Topflag,leftflag
' The size of the advertising picture
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 is picture 1 is a flash file
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 "</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 script] The following is a code fragment:
file://***************** Floating Advertising Display class ****************************************************
file://*: The fish that died in the water
file://* scripting language: Javascript
file://* usage:
file://* var adver=new adverclass
file://* adver.setobjname ("Adver"); file://This can't be settime, so it's no use.
file://* Adver.setdivid (1); file://, you don't have to.
file://* Adver.setimagetype (1); file://set to 0 o'clock or do not write this sentence is a normal picture, 1 for Flash animation files
file://* adver.setimagepx (299,87); file://set the width and height of the picture
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/"," What is this ");
file://* var adver1=new adverclass ();
file://* adver1.showadver ("Img.gif", "http://www.chinese.bj.cn/", "What is this");
file://* SetTimer ();
file://* file://because the class cannot write settime so had to take out to write-_-## (VBS script unexpectedly can. Aggravation
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; Delay value of file://time
var topstep=2,leftstep=3; How much file://one step
var Inter;
file://here is when the divID value is not set externally to ensure that the layer ID is unique
Divid=math.round (Math.random () *100000)
Type of file://ad 0 = ordinary picture 1=flash advertising picture
This.setimagetype=function (stype) {
if (stype!=1&&stype!=0) {stype=0;}
Imagetype=stype;
}
file://variable name of external call
This.setobjname=function (sname) {objname=sname;}
Height and width of file://advertising picture
This.setimagepx=function (iwidth,iheight) {
if (!isnan (iwidth)) {
Imagewidth=iwidth;
}else{
imagewidth=0;
}
if (!isnan (iheight)) {
Imageheight=iheight;
}else{
imageheight=0;
}
}
FILE://set the ID value of the layer where the advertisement is located
This.setdivid=function (idiv) {divid=idiv;}
file://main function, display ad code
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://get the width of the picture
Offwidth=objdiv.offsetwidth;
Offheight=objdiv.offsetheight;
file://the starting position of a random display ad
Ileft=math.round (Math.random () * (width-offwidth));
Itop=math.round (Math.random () * (height-offheight));
Objdiv.style.pixelleft=ileft;
Objdiv.style.pixeltop=itop;
file://start regularly
File://startTimer ();
}
file://main function, floating swimming display ads
This.floatscroll=function () {
var irnd;
Irnd=math.round (Math.random () *100); file://This value is to enable multiple graphs to be displayed with different trajectories
if (objdiv==null) return;
ObjDiv.style.pixelLeft = ILeft + document.body.scrollLeft;
ObjDiv.style.pixelTop = Itop + document.body.scrollTop;
if (irnd>98) {Leftflag=!leftflag;}
Irnd=math.round (Math.random () *100);
if (irnd>99) {Topflag=!topflag;}
if (Leftflag) {
Ileft=ileft+leftstep*math.random ();
}else{
Ileft=ileft-leftstep*math.random ();
}
if (Topflag) {
Itop=itop+topstep*math.random ();
}else{
Itop=itop-topstep*math.random ();
}
if (ileft<0) {
ileft=0;
Leftflag=true;
}
else if (ileft>width-offwidth) {
Ileft=width-offwidth;
Leftflag=false;
}
if (itop<0) {
Itop=0;
Topflag=true;
}
else if (itop>height-offheight) {
Itop=height-offheight;
Topflag=false;
}
}
file://a picture of a timed mobile ad
function Starttimer () {
if (objname== "") return;
File://alert (objname+ ". Floatscroll ();");
File://inter=setInterval (objname+ ". Floatscroll ()", delay);
}
file://HTML code to display a picture
function showimagehtml (adimgsrc,adhref,adtitle) {
var swidth,sheight;
if (imagewidth<5) {
Swidth= "";
}else{
Swidth= "Width= '" "+imagewidth+" ";
}
if (imageheight<5) {
Sheight= "";
}else{
sheight= "height= '" "+imageheight+" ";
}
document.write ("<div id= ' img" +divid+ "style= ' Position:absolute;") > ");
document.write ("<a href= '" +adhref+ "' target= ' _blank '" title= ' "+adtitle+" ' > ");
document.write ("document.write ("</a></div>");
}
file://HTML code to display flash files
function showflashhtml (adimgsrc,adhref,adtitle) {
var swidth,sheight;
if (imagewidth<5) {
Swidth= "width= ' 80 '";
}else{
Swidth= "Width= '" "+imagewidth+" ";
}
if (imageheight<5) {
sheight= "height= ' 80 '";
}else{
sheight= "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 ' "+swidth+sheight+" align= ' middle ' > ");
document.write ("<param name= ' movie ' value= '" +adimgsrc+ "' >");
document.write ("<param name= ' quality ' value= ' High ' >");
document.write ("<embed src=" "+adimgsrc+" "+swidth+sheight+" quality= ' high ' pluginspage= ' http:// Www.macromedia.com/go/getflashplayer ' type= ' application/x-shockwave-flash ' ></embed></object> ');
document.write ("</a></div>");
}
}
Sample code (including the use of two scripts):
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<HTML>
<HEAD>
<TITLE> Floating Ads Display Script class demo </TITLE>
</HEAD>
<BODY>
<!--vbs script version of the Ad Display class sample program-->
<script language= "VBScript" src= "Advervbs.vbs" ></script>
<script language= "VBScript" >
Dim Adver,adver1
Set adver=new Adverclass
Adver.objname= "Adver"
Adver.divid=20
Adver.printhtml "Img.gif", "http://www.chinese.bj.cn/", "What is this?"
Set adver1=new Adverclass
Adver1.objname= "Adver1"
Adver1.imgtype=1
adver1.imagewidth=299
adver1.imageheight=87
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/"," What is this? "
</script>
<!--JS script version of the Ad Display class sample program-->
<script language= "Javascript" src= "Adverclass.js" ></script>
<script language= "Javascript" >
var adver=new adverclass ();
Adver.setobjname ("Adver");
Adver.setdivid (1);
Adver.setimagetype (1);
ADVER.SETIMAGEPX (299,87);
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/"," What is this ");
var adver1=new adverclass ();
Adver1.showadver ("Img.gif", "http://www.chinese.bj.cn/", "What is this");
SetTimer ();
function SetTimer () {
Adver.floatscroll ();
Adver1.floatscroll ();
SetTimeout ("SetTimer ()", 80);
}
</script>
</BODY>
</HTML>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.