校内网DIY欢迎您的到来 - www.xiaoneidiy.com

允许关闭

来源: 作者: 发布时间:2008-10-23 浏览次数:
.[允许关闭]
    与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码:

var delta=0.015;
    var collection;
    var closeB=false;
    function floaters() {
    this.items = [];
    this.addItem = function(id,x,y,content)
    {
    document.write('<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'">'+content+'</DIV>');
   
    var newItem = {};
    newItem.object = document.getElementById(id);
    newItem.x = x;
    newItem.y = y;
   
    this.items[this.items.length] = newItem;
    }
    this.play = function()
    {
    collection = this.items
    setInterval('play()',30);
    }
    }
    function play()
    {
    if(screen.width<=800 || closeB)
    {
    for(var i=0;i<collection.length;i++)
    {
    collection.object.style.display = 'none';
    }
    return;
    }
    for(var i=0;i<collection.length;i++)
    {
    var followObj = collection.object;
    var followObj_x = (typeof(collection.x)=='string'?eval(collection.x):collection.x);
    var followObj_y = (typeof(collection.y)=='string'?eval(collection.y):collection.y);
   
    if(followObj.offsetLeft!=(document.body.scrollLeft+followObj_x)) {
    var dx=(document.body.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
    dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
    followObj.style.left=followObj.offsetLeft+dx;
    }
   
    if(followObj.offsetTop!=(document.body.scrollTop+followObj_y)) {
    var dy=(document.body.scrollTop+followObj_y-followObj.offsetTop)*delta;
    dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
    followObj.style.top=followObj.offsetTop+dy;
    }
    followObj.style.display = '';
    }
    }
    function closeBanner()
    {
    closeB=true;
    return;
    }
   
    var theFloaters = new floaters();
    //
    theFloaters.addItem('followDiv1','document.body.clientWidth-100',0,'<a  href=http://www.dfeng.net target=_blank><img src=ad/doublead/right.gif width=100 height=554 border=0></a><br><br><img src=ad/doublead/close.gif >');
    theFloaters.addItem('followDiv2',0,0,'<a  href=http://www.dfeng.net target=_blank><img src=ad/doublead/ad_ad.gif width=100 height=400 border=0 ></a><br><br><img src=ad/doublead/close.gif >');
    theFloaters.play();


   把上面的代码分别另存为两个JS文件,然后在想实现此效果的页面用
   
    <script type="text/javascript" language="javascript1.2" src="*.js"></SCRIPT>
   
    调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!

上一篇:JS代码效果大全之广告篇   下一篇:没有了

[TOP] [评论(0条)]


本月HOT代码排名

您可能喜欢的文章

Copyright @2008 www.xiaoneidiy.com All Rights Reserved 校内网DIY是网络代码制作推广主力军,只为你能找到满意的代码,DIY校内网原能成为你的网络家园!