网站首页 > 网页设计教程 > Javascript教程 > 网页对联广告代码效果大全

网页对联广告代码效果大全

  • 作者:互联网
  • 时间:2009-06-08 18:25:56

现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,下面就是实现效果所需代码:


  var de***=0.015
    var collection;
    function floaters() {
        th***items ;   = [];
        th***addItem ;   = function(id,x,y,content)
                  {
                    do***ent.write('

'+content+'
');
                  
                    var newItem                = {};
                    ne***em.object ;           = do***ent.getElementById(id);
                    ne***em.x ;               = x;
                    ne***em.y ;               = y;

                    th***items[th***items.length]        = newItem;
                  }
        th***play ;   = function()
                  {
                    collection                = th***items
                    setInterval('play()',10);
                  }
        }
        function play()
        {
            if(sc***n.width<=800)
            {
                for(var i=0;i<co***ction.length;i++)
                {
                    collection[i].o***ct.style.display ;   = 'none';
                }
                return;
            }
            for(var i=0;i<co***ction.length;i++)
            {
                var followObj        = collection[i].object;
                var followObj_x        = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
                var followObj_y        = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);

                if(fo***wObj.offsetLeft!=(do***ent.body.scrollLeft+followObj_x)) {
                    var dx=(do***ent.body.scrollLeft+followObj_x-fo***wObj.offsetLeft)*delta;
                    dx=(dx>0?1:-1)*M***.ceil(Math.abs(dx));
                    followObj.style.left=fo***wObj.offsetLeft+dx;
                    }

                if(fo***wObj.offsetTop!=(do***ent.body.scrollTop+followObj_y)) {
                    var dy=(do***ent.body.scrollTop+followObj_y-fo***wObj.offsetTop)*delta;
                    dy=(dy>0?1:-1)*M***.ceil(Math.abs(dy));
                    followObj.style.top=fo***wObj.offsetTop+dy;
                    }
                fo***wObj.style.display ;   = '';
            }
        }  
      
    var theFloaters        = new floaters();
    th***oaters.addItem('followDiv1','do***ent.body.clientWidth-100',0,'
');
    th***oaters.addItem('followDiv2',0,0,'
');
    th***oaters.play(); 
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可!注意修改https://images.downcodes.com广告图片地址和连接地址!


鼠标感应]

与前面一个代码不同的是,当鼠标移动到广告图片上是可以感应显示另外设置好的广告大图效果,下面就是实现效果所需代码:


function bigshow(){
do***ent.all.div_250.style.visibility = 'visible';
do***ent.all.div_80.style.visibility = 'hidden';
}
function bighide(){
do***ent.all.div_80.style.visibility = 'visible';
do***ent.all.div_250.style.visibility = 'hidden';
}

var ad_80= new Array(1);
var ad_250= new Array(1);

ad_80[0]="href=http***ww.dfeng.net target=_blank>";
ad_250[0]="href=http***ww.dfeng.net target=_blank>";

var imgheight;
var fubioleft;
window.sc***n.width>800 ? fubioleft=15:fubioleft=15

do***ent.write('

');

ad_now = new Date();
ad_id= ad***w.getSeconds() %1

 

var adhead1="

";
var adhead2="
";

//var adhead1="

";
//var adhead2="
");

 

do***ent.write ("

");
se***onError=null;
currentX = currentY = 0;
     whichIt = null;         
     lastScrollX = 0; lastScrollY = 0;
     NS = (do***ent.layers) ? 1 : 0;
     IE = (do***ent.all) ? 1: 0;   
     function heartBeat() {
      if(IE) {
  diffY = do***ent.body.scrollTop;
  diffX = do***ent.body.scrollLeft; }
             if(NS) {
   diffY = se***pageYOffset; diffX = se***pageXOffset; }
      if(diffY != lastScrollY) {
                     percent = .5 * (diffY - lastScrollY);
                     if(percent > 0) percent = Ma***ceil(percent);
                     else percent = Ma***floor(percent);
         if(IE) do***ent.all.floater_left.style.pixelTop += percent;
         if(NS) do***ent.floater_left.top += percent;
                     lastScrollY = lastScrollY + percent;
         }
      if(diffX != lastScrollX) {
       percent = .5 * (diffX - lastScrollX);
       if(percent > 0) percent = Ma***ceil(percent);
       else percent = Ma***floor(percent);
       if(IE) do***ent.all.floater_left.style.pixelLeft += percent;
       if(NS) do***ent.floater_left.left += percent;
       lastScrollX = lastScrollX + percent;
      }
     }

     if(NS || IE) action = wi***w.setInterval("heartBeat()",1);var ad_80= new Array(1);
var ad_250= new Array(1);

ad_80[0]="href=http***ww.dfeng.net target=_blank>";
ad_250[0]="href=http***ww.dfeng.net target=_blank>";

var imgheight;
var fubioleft;
window.sc***n.width>800 ? fubioleft=15:fubioleft=15

do***ent.write('

');

ad_now = new Date();
ad_id= ad***w.getSeconds() %1


function myload()
{
if (na***ator.appName == "Netscape")
{
do***ent.div_right_80.pageX=+wi***w.innerWidth-130;
do***ent.div_right_250.pageX=+wi***w.innerWidth-300;
mymove();
}
else
{
di***ight_80.style.left=document.body.offsetWidth-130;
di***ight_250.style.left=do***ent.body.offsetWidth-300;
mymove();
}
}

function mymove()
{
if(do***ent.ns)
{
do***ent.div_right_80.left=pageXOffset+wi***w.innerWidth-130;
do***ent.div_right_250.left=pageXOffset+wi***w.innerWidth-300;
setTimeout("mymove();",20)
}
else
{
div_right_80.style.left=do***ent.body.scrollLeft+do***ent.body.offsetWidth-145;
div_right_250.style.left=do***ent.body.scrollLeft+do***ent.body.offsetWidth-300;
setTimeout("mymove();",20)
}
}

 

var adhead1="

";
var adhead2="
";

do***ent.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"

");

myload()

do***ent.write ("

");
se***onError=null;
currentX_right = currentY_right = 0;
     whichIt_right = null;         
     lastScrollX_right = 0; lastScrollY_right = 0;
     NS = (do***ent.layers) ? 1 : 0;
     IE = (do***ent.all) ? 1: 0;   
     function heartBeat_right() {
      if(IE) {
  diffY_right = do***ent.body.scrollTop;
  diffX_right = do***ent.body.scrollLeft; }
             if(NS) {
   diffY_right = se***pageYOffset; diffX_right = se***pageXOffset; }
      if(diffY_right != lastScrollY_right) {
                     percent_right = .5 * (diffY_right - lastScrollY_right);
                     if(percent_right > 0) percent_right = Ma***ceil(percent_right);
                     else percent_right = Ma***floor(percent_right);
         if(IE) do***ent.all.floater_right.style.pixelTop += percent_right;
         if(NS) do***ent.floater_right.top += percent_right;
                     lastScrollY_right = lastScrollY_right + percent_right;
         }
      if(diffX_right != lastScrollX_right) {
       percent_right = .5 * (diffX_right - lastScrollX_right);
       if(percent_right > 0) percent_right = Ma***ceil(percent_right);
       else percent_right = Ma***floor(percent_right);
       if(IE) do***ent.all.floater_right.style.pixelLeft += percent_right;
       if(NS) do***ent.floater_right.left += percent_right;
       lastScrollX_right = lastScrollX_right + percent_right;
      }
     }

     if(NS || IE) action = wi***w.setInterval("heartBeat_right()",1);
function bigshow_right(){
do***ent.all.div_right_250.style.visibility = 'visible';
do***ent.all.div_right_80.style.visibility = 'hidden';
}
function bighide_right(){
do***ent.all.div_right_80.style.visibility = 'visible';
do***ent.all.div_right_250.style.visibility = 'hidden';
}do***ent.write('');
do***ent.write('');
do***ent.write('');
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用



调用即可,*代表你另存的文件名!注意修改https://images.downcodes.com广告图片地址和连接地址!

 

与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码:


var de***=0.015;
var collection;
var closeB=false;
function floaters() {
  th***items = [];
  th***addItem = function(id,x,y,content)
      {
     do***ent.write('

'+content+'
');
   
     var newItem    = {};
     ne***em.object ;  = do***ent.getElementById(id);
     ne***em.x ;   = x;
     ne***em.y ;   = y;

     th***items[th***items.length]  = newItem;
      }
  th***play = function()
      {
     collection    = th***items
     setInterval('play()',30);
      }
  }
  function play()
  {
   if(sc***n.width<=800 || closeB)
   {
    for(var i=0;i<co***ction.length;i++)
    {
     collection[i].o***ct.style.display = 'none';
    }
    return;
   }
   for(var i=0;i<co***ction.length;i++)
   {
    var followObj  = collection[i].object;
    var followObj_x  = (typeof(collection[i].x)=='string'?eval(collection[i].x):collection[i].x);
    var followObj_y  = (typeof(collection[i].y)=='string'?eval(collection[i].y):collection[i].y);

    if(fo***wObj.offsetLeft!=(do***ent.body.scrollLeft+followObj_x)) {
     var dx=(do***ent.body.scrollLeft+followObj_x-fo***wObj.offsetLeft)*delta;
     dx=(dx>0?1:-1)*M***.ceil(Math.abs(dx));
     followObj.style.left=fo***wObj.offsetLeft+dx;
     }

    if(fo***wObj.offsetTop!=(do***ent.body.scrollTop+followObj_y)) {
     var dy=(do***ent.body.scrollTop+followObj_y-fo***wObj.offsetTop)*delta;
     dy=(dy>0?1:-1)*M***.ceil(Math.abs(dy));
     followObj.style.top=fo***wObj.offsetTop+dy;
     }
    fo***wObj.style.display = '';
   }
  }
  function closeBanner()
  {
   closeB=true;
   return;
  }

var theFloaters  = new floaters();
//
th***oaters.addItem('followDiv1','do***ent.body.clientWidth-100',0,'href=http***ww.dfeng.net target=_blank>

');
th***oaters.addItem('followDiv2',0,0,'href=http***ww.dfeng.net target=_blank>

');
th***oaters.play();
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可,*代表你另存的文件名!注意修改https://images.downcodes.com广告图片地址和连接地址!

 


浮动对联广告---之左侧代码

如果您想只有一侧显示的话,下面是实现左侧效果所需代码:


var ad_float_left_src ="图片地址";
var ad_float_left_url ="地址";
var ad_float_left_type = "";
do***ent.ns = na***ator.appName == "Microsoft Internet Explorer"

var imgheight_close
var imgleft
window.sc***n.width>800 ? imgheight_close=120:imgheight_close=120
window.sc***n.width>800 ? imgleft=8:imgleft=122
function myload()
{
myleft.style.top=do***ent.body.scrollTop+do***ent.body.offsetHeigh
t-imgheight_close;
my***t.style.left=imgleft;
leftmove();
}
function leftmove()
{
myleft.style.top=do***ent.body.scrollTop+do***ent.body.offsetHeigh
t-imgheight_close;
my***t.style.left=imgleft;
setTimeout("leftmove();",50)
}

function MM_reloadPage(init) {  //reloads the window if Nav4
resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&
(parseInt(appVersion)==4)) {
    do***ent.MM_pgW=innerWidth; do***ent.MM_pgH=innerHeight;
onresize=MM_reloadPage; }}
  else if (innerWidth!=d***ment.MM_pgW || innerHeight!
=d***ment.MM_pgH) lo***ion.reload();
}
MM_reloadPage(true)

function close_float_left(){
my***t.style.visibility='hidden';
}

do***ent.write("

"
+""
+""
+"
");

if(do***ent.ns){
if(ad_float_left_type!="swf")
do***ent.write("= '_blank'>height=31 border=0>");
else
do***ent.write("quality=high  WIDTH=80 HEIGHT=80 TYPE='application/x-shockwave-
flash' id=changhongout >");

do***ent.write("

align=right>class=closefloat>关闭
"
+"
");

myload()}
把上面的代码另存为一个*.JS文件,然后在想实现此效果的页面用



调用即可,*代表你另存的文件名!注意修改https://images.downcodes.com广告图片地址和连接地址!相应的参数可以根据页面自行调整。