网站首页 > 网页设计教程 > Javascript教程 > JavaScript 对联广告、漂浮广告封装类(IE,FF,Opera,Safari,Chrome)

JavaScript 对联广告、漂浮广告封装类(IE,FF,Opera,Safari,Chrome)

  • 作者:互联网
  • 时间:2009-06-11 16:32:24

代码:


 程序代码
/*
对联广告调用
第一个参数为ID,第二个参数图片,第三个参数广告距离顶部的距离,
第四个参数表示左右(true代表左,false代表右),第五个参数对联广告的宽度
*/
new float_ad("ad_l","",50,true,64);
new float_ad("ad_r","",50,false,64);

/*
漂浮广告调用
第一个参数中的url代表漂浮广告的图片URL地址(必选项),link链接到页面网址,alt图片提示文字,width图片的宽度(可选项,默认120),heihgt图片的高度(可选项,默认120)
第二个参数中的代表漂浮广告的初始位置,由参数left和top指定
第三个参数代表浮动速度,0为静止,越小浮动速度越快
*/
new move_ad({url:"https://images.downcodes.com/u/info_img/2009-06/11/2009Cherry.gif",link:"http://jz***h.org.cn/html/zixun/zuixingonggao/2009327/zxgg47926848.html",alt:"关于招募“2009中国·大连国际樱桃节”志愿者的通知",width:200,height:200},{left:40,top:160},20);

//核心代码
function $(element){
    if(ar***ents.length>1){
        for(var i=0,elements=[],length=ar***ents.length;i            el***nts.push($(arguments[i]));
        return elements;
    }
    if(typeof element=="string")
        return do***ent.getElementById(element);
    else
        return element;
}
Fu***ion.prototype.bind=function(object){
    var method=this;
    return function(){
        me***d.apply(object,arguments);
    }
}
var Class={
    create:function(){
        return function(){
            th***initialize.apply(this,arguments);
        }
    }
}
Ob***t.extend=function(destination,resource){
    for(var property in resource){
        destination[property]=resource[property];   
    }
    return destination;
}
//对联广告类http://www.knowsky.com/article.asp?typeid=36
var fl***_ad=Class.create();
fl***_ad.prototype={
    initialize:function(id,content,top,left,width){
        do***ent.write('

'+content+'
');
        this.id=$(id);
        th***top=top;
        if(!!left){
            th***id.style.left="8px";   
        }else{
            th***id.style.left=(do***ent.documentElement.clientWidth-width-8)+"px";
            wi***w.onresize=function(){
                th***id.style.left=(do***ent.documentElement.clientWidth-width-8)+"px";
            }.bind(this);
        }
        th***id.style.top=top+"px";
       
        th***interId=setInterval(th***scroll.bind(this),20);
    },
    scroll:function(){
        th***stmnStartPoint = parseInt(th***id.style.top, 10);
        th***stmnEndPoint =d***ment.documentElement.scrollTop+ this.top;
        if(na***ator.userAgent.indexOf("Chrome")>0){
            th***stmnEndPoint=document.body.scrollTop+this.top;   
        }
        if ( th***stmnStartPoint != th***stmnEndPoint ) {
                th***stmnScrollAmount = Ma***ceil( Math.abs( th***stmnEndPoint - th***stmnStartPoint ) / 15 );
                th***id.style.top = parseInt(th***id.style.top, 10) + ( ( th***stmnEndPoint<th***stmnStartPoint ) ? -th***stmnScrollAmount : th***stmnScrollAmount )+"px";
        }
    }
}
//漂浮广告类
var mo***ad=Class.create();
mo***ad.prototype={
    initialize:function(imgOption,initPosition,delay){
        th***imgOptions=Object.extend({url:"",link:"",alt:"",width:120,height:120},imgOption||{});
        th***adPosition=Object.extend({left:40,top:120},initPosition||{});
        th***delay =delay;
        th***step = 1;
        th***herizonFlag=true;
        th***verticleFlag=true;
        this.id="ad_move_sg";
        var vHtmlString="
"+<span class="visiblesaf56">th***imgOptions.alt</span>+"
";
        do***ent.write(vHtmlString);
        this.id=$(this.id);
        th***intervalId=setInterval(th***scroll.bind(this),th***delay);
        th***id.onmouseover=this.stop.bind(this);
        th***id.onmouseout=this.start.bind(this);
    },
    scroll:function(){
        var L=T=0;
        var B=***ument.documentElement.clientHeight-this.id.offsetHeight;
        var R=***ument.documentElement.clientWidth-this.id.offsetWidth;
        th***id.style.left=th***adPosition.left+do***ent.documentElement.scrollLeft+"px";
        th***id.style.top=th***adPosition.top+do***ent.documentElement.scrollTop+"px";
        th***adPosition.left =th***adPosition.left + th***step*(th***herizonFlag?1:-1);
        if (th***adPosition.left < L) { th***herizonFlag = true; th***adPosition.left = L;}
        if (th***adPosition.left > R){ th***herizonFlag = false; th***adPosition.left = R;}
        th***adPosition.top =th***adPosition.top + th***step*(th***verticleFlag?1:-1);
        if(th***adPosition.top <= T){ th***verticleFlag=true; th***adPosition.top=T;}
        if(th***adPosition.top >= B){ th***verticleFlag=false; th***adPosition.top=B; }
    },
    stop:function(){
        clearInterval(th***intervalId);   
    },
    start:function(){
        th***intervalId=setInterval(th***scroll.bind(this),th***delay);   
    }
}