Home > Web Front-end > JS Tutorial > body text

js couplet ads, floating ad encapsulation classes (IE, FF, Opera, Safari, Chrome_advertising code

WBOY
Release: 2016-05-16 18:41:06
Original
1302 people have browsed it

/*
Couplet ad call
The first parameter is the ID, the second parameter is the picture, the third parameter is the distance between the advertisement and the top,
The fourth parameter represents left and right (true represents left, false represents Right), the fifth parameter is the width of the couplet advertisement
*/
new float_ad("ad_l","" ,50,true,64);
new float_ad("ad_r","",50,false,64);

/*
Floating ad call
The url in the first parameter represents the image URL address of the floating ad (required), link to the page URL, alt image prompt text, width image Width (optional, default 120), height of heihgt image (optional, default 120)
The second parameter represents the initial position of the floating advertisement, which is specified by the parameters left and top
The third parameter represents Floating speed, 0 is static, the smaller it is, the faster the floating speed is .jb51.net",alt:"Notice on Recruiting Volunteers for "2009 China·Dalian International Cherry Festival",width:200,height:200},{left:40,top:160},20);


Copy code The code is as follows:

//核心代码
function $(element){
if(arguments.length>1){
for(var i=0,elements=[],length=arguments.length;ielements.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;
}
//对联广告类
var float_ad=Class.create();
float_ad.prototype={
initialize:function(id,content,top,left,width){
document.write('
' content '
');
this.id=$(id);
this.top=top;
if(!!left){
this.id.style.left="8px";
}else{
this.id.style.left=(document.documentElement.clientWidth-width-8) "px";
window.onresize=function(){
this.id.style.left=(document.documentElement.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 =document.documentElement.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}
}
}
//漂浮广告类
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="
" this.imgOptions.alt "
";
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.documentElement.clientHeight-this.id.offsetHeight;
var R=document.documentElement.clientWidth-this.id.offsetWidth;
this.id.style.left=this.adPosition.left document.documentElement.scrollLeft "px";
this.id.style.top=this.adPosition.top document.documentElement.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);
}
}
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template