Javascript couplet advertisement, floating advertisement encapsulation class (ie, FF, opera, Safari, Chrome)

Source: Internet
Author: User

/*
Couplet advertisement call
The first parameter is ID, the second parameter is image, and the third parameter is the distance from the advertisement to the top,
The fourth parameter indicates left and right (true indicates left, false indicates right), and the fifth parameter indicates the width of the couplet advertisement.
*/
New float_ad ("ad_l", "New float_ad ("ad_r", "

/*
Floating ad call
The URL in the first parameter represents the URL of the floating ad image (required), link to the page url, ALT image prompt text, width image width (optional, default 120 ), heihgt Image Height (optional, 120 by default)
The second parameter represents the initial position of the floating AD, which is specified by the left and top parameters.
The third parameter indicates the floating speed. 0 indicates the static speed. The smaller the floating speed, the faster the floating speed.
*/
New move_ad ({URL: "/system/uploads/allimg/090504/2346400 .gif", link:" http://jzyouth.org.cn/html/zixun/zuixingonggao/2009327/zxgg47926848.html ", alt: "Notice on recruiting volunteers for" 2009 China Dalian International Cherry Festival ", width: 200, height: 200 },{ left: 40, top: 160}, 20 );

// Core Code
Function $ (element ){
If (arguments. length> 1 ){
For (VAR I = 0, elements = [], length = arguments. length; I <length; I ++)
Elements. Push ($ (arguments [I]);
Return elements;
}
If (typeof element = "string ")
Return document. getelementbyid (element );
Else
Return element;
}
Function. Prototype. Bind = function (object ){
VaR method = this;
Return function (){
Method. Apply (object, arguments );
}
}
VaR class = {
Create: function (){
Return function (){
This. Initialize. Apply (this, arguments );
}
}
}
Object. Extend = function (destination, resource ){
For (VAR property in resource ){
Destination [property] = Resource [property];
}
Return destination;
}
// Couplet advertising class http://www.knowsky.com/article.asp? Typeid = 36
VaR float_ad = Class. Create ();
Float_ad.prototype = {
Initialize: function (ID, content, top, left, width ){
Document. Write ('<Div id =' + ID + 'style = "position: absolute;">' + content + '</div> ');
This. ID = $ (ID );
This. Top = top;
If (!! Left ){
This. Id. style. Left = "8px ";
} Else {
This.id.style.left.pdf (document.doc umentelement. clientWidth-width-8) + "PX ";
Window. onresize = function (){
This.id.style.left.pdf (document.doc umentelement. clientWidth-width-8) + "PX ";
}. BIND (this );
}
This. Id. style. Top = Top + "PX ";

This. interid = setinterval (this. Scroll. BIND (this), 20 );
},
Scroll: function (){
This. stmnstartpoint = parseint (this. Id. style. Top, 10 );
This. stmnendpoint upload document.doc umentelement. scrolltop + this. Top;
If (navigator. useragent. indexof ("Chrome")> 0 ){
This. stmnendpoint = Document. Body. scrolltop + this. Top;
}
If (this. stmnstartpoint! = This. stmnendpoint ){
This. stmnscrollamount = math. Ceil (math. Abs (this. stmnendpoint-This. stmnstartpoint)/15 );
This. Id. style. Top = parseint (this. Id. style. Top, 10) + (this. stmnendpoint <this. stmnstartpoint )? -This. stmnscrollamount: This. stmnscrollamount) + "PX ";
}
}
}
// Floating Advertisement
VaR move_ad = Class. Create ();
Move_ad.prototype = {
Initialize: function (imgoption, initposition, delay ){
This. imgoptions = object. Extend ({URL: "", link: "", alt: "", width: 120, height: 120}, imgoption || {});
This. adposition = object. Extend ({left: 40, top: 120}, initposition || {});
This. Delay = delay;
This. Step = 1;
This. herizonflag = true;
This. verticleflag = true;
This. ID = "ad_move_sg ";
VaR vhtmlstring = "<Div id = '" + this. ID + "'style = 'position: absolute; left:" + this. adposition. left + "PX; top:" + this. adposition. top + "PX; width:" + this. imgoptions. width + "PX ;";
Vhtmlstring + = "height:" + this. imgoptions. height + "PX; Z-index: 10; '> <a href ='" + this. imgoptions. link + "'target = '_ blank 'title ='" + this. imgoptions. alt + "'> </a> </div> ";
Document. Write (vhtmlstring );
This. ID = $ (this. ID );
This. intervalid = setinterval (this. Scroll. BIND (this), this. Delay );
This. Id. onmouseover = this. Stop. BIND (this );
This. Id. onmouseout = This. Start. BIND (this );
},
Scroll: function (){
VaR L = T = 0;
VaR B =document.doc umentelement. clientHeight-this.id.offsetHeight;
VaR r=document.doc umentelement. clientWidth-this.id.offsetWidth;
This.id.style.left?this.adposition.left?document.doc umentelement. scrollleft + "PX ";
This.id.style.topw.this.adposition.top?document.doc umentelement. scrolltop + "PX ";
This. adposition. Left = This. adposition. Left + this. Step * (this. herizonflag? 1:-1 );
If (this. adposition. Left <L) {This. herizonflag = true; this. adposition. Left = L ;}
If (this. adposition. Left> r) {This. herizonflag = false; this. adposition. Left = r ;}
This. adposition. Top = This. adposition. Top + this. Step * (this. verticleflag? 1:-1 );
If (this. adposition. Top <= T) {This. verticleflag = true; this. adposition. Top = T ;}
If (this. adposition. Top> = B) {This. verticleflag = false; this. adposition. Top = B ;}
},
Stop: function (){
Clearinterval (this. intervalid );
},
Start: function (){
This. intervalid = setinterval (this. Scroll. BIND (this), this. Delay );
}
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.