您现在的位置:首页 >> 建站经验 >> 内容

网站对联广告(网站两边广告条,网站两侧广告)代码

时间:2009/9/17 9:16:49 点击:6428

  核心提示:现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,本文介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,而且与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下...

现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,本文介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,而且与前面两个代码不同的是,广告图下方增加了一个图片按纽,允许访客点击关闭广告图片,下面文本框中就是实现效果所需代码:

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[i].object.style.display = 'none';
  }
  return;
  }
  for(var i=0;i<collection.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(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 onClick="closeBanner();" href=http://www.webjx.com target=_blank><img src=/img2/js050121_1.gif width=100 height=400 border=0></a><br><img src="/img2/js050121_close.gif" onClick="closeBanner();">');
theFloaters.addItem('followDiv2',0,0,'<a onClick="closeBanner();" href=http://www.webjx.com target=_blank><img src=/img2/js050121_2.gif width=100 height=400 border=0 ></a><br><img src="/img2/js050121_close.gif" onClick="closeBanner();">');
theFloaters.play();

 

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

 

网页两侧浮动广告代码
关键词: 网页两侧浮动广告代码                                          

 

    在BODY内加入以下代码:

***********************************************

"< DIV id=floater1 style="Z-INDEX: 100; LEFT: 10px; VISIBILITY: visible; WIDTH: 100px; POSITION: absolute; TOP: 160px; height: 100px;" >
左边的東西,可以是图片,表格
< /DIV >
< DIV id=floater style="Z-INDEX: 100; RIGHT: 10px; VISIBILITY: visible; WIDTH: 100px; POSITION: absolute; TOP: 160px; left: 890px;" >
右边的東西,可以是图片,表格
< /DIV >"

 

 

 

***********************************************

   menus.js的代码如下:

***********************************************

self.onError = null;

currentX = currentY = 0;

whichIt = null;

lastScrollX = 0; lastScrollY = 0;

NS = (document.layers) ? 1 : 0;

IE = (document.all) ? 1: 0;


function heartBeat(objectid) {

 if(IE) { diffY = document.body.scrollTop; diffX = document.body.scrollLeft; }

 if(NS) { diffY = self.pageYOffset; diffX = self.pageXOffset; }

 if(diffY != lastScrollY) {

  percent = .1 * (diffY - lastScrollY);

  if(percent > 0) percent = Math.ceil(percent);

  else percent = Math.floor(percent);

  if(IE) {

   objectid = objectid.split(";");

   for (i = 0; i < objectid.length; i++) eval("document.all."+objectid[i]).style.pixelTop += percent;

  }

  if(NS) {

   objectid = objectid.split(";");

   for (i = 0; i < objectid.length; i++) eval("document."+objectid[i]).top += percent;

  }

  lastScrollY = lastScrollY + percent;

 }

 if(diffX != lastScrollX) {

  percent = .1 * (diffX - lastScrollX);

  if(percent > 0) percent = Math.ceil(percent);

  else percent = Math.floor(percent);

  if(IE) {

   objectid = objectid.split(";");

   for (i = 0; i < objectid.length; i++) eval("document.all."+objectid[i]).style.pixelLeft += percent;

  }

  if(NS) {

   objectid = objectid.split(";");

   for (i = 0; i < objectid.length; i++) eval("document."+objectid[i]).left += percent;   

  }

  lastScrollX = lastScrollX + percent;

 } 

}


if(NS || IE) action = window.setInterval("heartBeat('floater;floater1')", 2);


***********************************************

    OK,成功就这么简单!DIV内的文字可以换成图片和表格,ID不改就行了...

    另外,记得以上代码为了不干扰本文章的显示,在"<>"中多加了空格,拷贝到文档以后记得修改.

 


--------------------------------------------------------------------------------

 

    除了上述方法之外,还另从其他网站搜集到另一种实现方法,方法如下:

    在显示页面中加入:

< SCRIPT language="JavaScript" src="js/flr.js" >< /SCRIPT >
< SCRIPT language="JavaScript" src="js/fll.js" >< /SCRIPT >

---------------------------flr.js------------------------------------
var imgheight
document.ns = navigator.appName == "Netscape"
window.screen.width>800 ? imgheight=100:imgheight=120
function myload()
{
if (navigator.appName == "Netscape")
{document.dangdang.pageY=pageYOffset+window.innerHeight-imgheight-0;
document.dangdang.pageX=+window.innerWidth-107;
mymove();
}
else
{
dangdang.style.top=document.body.scrollTop+document.body.offsetHeight-imgheight-0;
dangdang.style.left=document.body.offsetWidth-107;
mymove();
}
}
function mymove()
{
if(document.ns)
{
document.dangdang.top=pageYOffset+window.innerHeight-imgheight-0;
document.dangdang.left=pageXOffset+window.innerWidth-107;
setTimeout("mymove();",50)
}
else
{
dangdang.style.top=document.body.scrollTop+document.body.offsetHeight-imgheight-0;
dangdang.style.left=document.body.scrollLeft+document.body.offsetWidth-107;
setTimeout("mymove();",50)
}
}

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

 if (navigator.appName == "Netscape")
{
document.write("href=#'> src='*.GIF' width='80' height='80'>");
myload()}
else
{
document.write("


");
myload()
}

 

-------------------------fll.js--------------------------------------
var imgheight
var imgleft
document.ns = navigator.appName == "Netscape"
window.screen.width>800 ? imgheight=110:imgheight=110
window.screen.width>800 ? imgleft=5:imgleft=5
function myload()
{
if (navigator.appName == "Netscape")
{document.myleft.pageY=pageYOffset+window.innerHeight-imgheight;
document.myleft.pageX=imgleft;
leftmove();
}
else
{
myleft.style.top=document.body.scrollTop+document.body.offsetHeight-imgheight;
myleft.style.left=imgleft;
leftmove();
}
}
function leftmove()
{
if(document.ns)
{
document.myleft.top=pageYOffset+window.innerHeight-imgheight
documen

t.myleft.left=imgleft;
setTimeout("leftmove();",80)
}
else
{
myleft.style.top=document.body.scrollTop+document.body.offsetHeight-imgheight;
myleft.style.left=imgleft;
setTimeout("leftmove();",80)
}
}

 

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

if (navigator.appName == "Netscape")
{
document.write("

href='http://www.yiwanzhan.cn/'>width='80' height='80'>");
myload()}
else
{
document.write("

");
myload()
}

 

 


--------------------------------------------------------------------------------

 

    当然,这种方法要比较麻烦一点,要做三个文件处理,喜欢用哪个,你自己挑吧!吼吼!

作者:冷月湖 录入:冷月湖 来源:原创
相关评论
发表我的评论
  • 大名:
  • 内容:
  • 亿万站网址导航-站长之家(www.yiwanzhan.cn) © 2006-2024 版权所有 All Rights Reserved.
  • Email:xiegr71@163.com 站长QQ:329700870 京ICP备07500142号