【参加讨论】 现在很多网站广告做的如火如荼,现在我就来介绍一下常见的对联浮动广告效果的代码使用方法,本文介绍的这种效果,在1024*768分辨率下正常显示,在800*600的分辨率下可以自动隐藏,以免遮住页面影响访问者浏览内容,而且与前面一个代码不同的是,当鼠标移动到广告图片上是可以感应显示另外设置好的广告大图效果,下面就是实现效果所需代码:
function bigshow(){
document.all.div_250.style.visibility = 'visible';
document.all.div_80.style.visibility = 'hidden';
}
function bighide(){
document.all.div_80.style.visibility = 'visible';
document.all.div_250.style.visibility = 'hidden';
}
var ad_80= new array(1);
var ad_250= new array(1);
ad_80[0]="<a href=http://www.dfeng.net target=_blank><img src="http://www.iyit.net/files/beyondpic/2006-5/5/06551002367806.gif" border=0></a>";
ad_250[0]="<a href=http://www.dfeng.net target=_blank><img src="http://www.iyit.net/files/beyondpic/2006-5/5/065510023795339.gif" border=0></a>";
var imgheight;
var fubioleft;
window.screen.width>800 ? fubioleft=15:fubioleft=15
document.write('<div id=floater_left style="z-index: 25; left:'+fubioleft+'px; width: 28px;position: absolute; top: 42px; height: 22px">');
ad_now = new date();
ad_id= ad_now.getseconds() %1
var adhead1="<div id=div_80 style='position:absolute; width:95px; height:62px; z-index:12' onmouseover=bigshow();>";
var adhead2="</div><div id=div_250 style='position:absolute; visibility: hidden; z-index:13;width: 80; height: 60' onmouseout=bighide();>";
//var adhead1="<div id=div_80 style='position:absolute; width:95px; height:62px; z-index:20' onmouseout='//mm_showhidelayers(\"div_250\",\"\",\"hide\")' onmouseover='mm_showhidelayers(\"div_250\",\"\",\"show\")'>";
//var adhead2="</div><div id=div_250 style='position:absolute; z-index:21;visibility: hidden; width: 80; height: 60' onmouseover='mm_showhidelayers(\"div_250\",\"\",\"show\")' onmouseout='mm_showhidelayers(\"div_250\",\"\",\"hide\")'>";
document.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"</div>");
document.write ("</div>");
self.onerror=null;
currentx = currenty = 0;
whichit = null;
lastscrollx = 0; lastscrolly = 0;
ns = (document.layers) ? 1 : 0;
ie = (document.all) ? 1: 0;
function heartbeat() {
if(ie) {
diffy = document.body.scrolltop;
diffx = document.body.scrollleft; }
if(ns) {
diffy = self.pageyoffset; diffx = self.pagexoffset; }
if(diffy != lastscrolly) {
percent = .5 * (diffy - lastscrolly);
if(percent > 0) percent = math.ceil(percent);
else percent = math.floor(percent);
if(ie) document.all.floater_left.style.pixeltop += percent;
if(ns) document.floater_left.top += percent;
lastscrolly = lastscrolly + percent;
}
if(diffx != lastscrollx) {
percent = .5 * (diffx - lastscrollx);
if(percent > 0) percent = math.ceil(percent);
else percent = math.floor(percent);
if(ie) document.all.floater_left.style.pixelleft += percent;
if(ns) document.floater_left.left += percent;
lastscrollx = lastscrollx + percent;
}
}
if(ns || ie) action = window.setinterval("heartbeat()",1);var ad_80= new array(1);
var ad_250= new array(1);
ad_80[0]="<a href=http://www.dfeng.net target=_blank><img src="http://www.iyit.net/files/beyondpic/2006-5/5/06551002374179.jpg" border=0></a>";
ad_250[0]="<a href=http://www.dfeng.net target=_blank><img src="http://www.iyit.net/files/beyondpic/2006-5/5/06551002374179.jpg" border=0></a>";
var imgheight;
var fubioleft;
window.screen.width>800 ? fubioleft=15:fubioleft=15
document.write('<div id=floater_right style="z-index: 25; left:'+fubioleft+'px; width: 28px;position: absolute; top: 42px; height: 22px">');
ad_now = new date();
ad_id= ad_now.getseconds() %1
function myload()
{
if (navigator.appname == "netscape")
{
document.div_right_80.pagex=+window.innerwidth-130;
document.div_right_250.pagex=+window.innerwidth-300;
mymove();
}
else
{
div_right_80.style.left=document.body.offsetwidth-130;
div_right_250.style.left=document.body.offsetwidth-300;
mymove();
}
}
function mymove()
{
if(document.ns)
{
document.div_right_80.left=pagexoffset+window.innerwidth-130;
document.div_right_250.left=pagexoffset+window.innerwidth-300;
settimeout("mymove();",20)
}
else
{
div_right_80.style.left=document.body.scrollleft+document.body.offsetwidth-145;
div_right_250.style.left=document.body.scrollleft+document.body.offsetwidth-300;
settimeout("mymove();",20)
}
}
var adhead1="<div id=div_right_80 style='position:absolute; width:95px; height:60px; z-index:12' onmouseover=bigshow_right();>";
var adhead2="</div><div id=div_right_250 style='position:absolute; visibility: hidden; z-index:13;width: 250; height: 250' onmouseout=bighide_right();><div align=right>";
document.write(adhead1+ad_80[ad_id]+adhead2+ad_250[ad_id]+"</div></div>");
myload()
document.write ("</div>");
self.onerror=null;
currentx_right = currenty_right = 0;
whichit_right = null;
lastscrollx_right = 0; lastscrolly_right = 0;
ns = (document.layers) ? 1 : 0;
ie = (document.all) ? 1: 0;
function heartbeat_right() {
if(ie) {
diffy_right = document.body.scrolltop;
diffx_right = document.body.scrollleft; }
if(ns) {
diffy_right = self.pageyoffset; diffx_right = self.pagexoffset; }
if(diffy_right != lastscrolly_right) {
percent_right = .5 * (diffy_right - lastscrolly_right);
if(percent_right > 0) percent_right = math.ceil(percent_right);
else percent_right = math.floor(percent_right);
if(ie) document.all.floater_right.style.pixeltop += percent_right;
if(ns) document.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 = math.ceil(percent_right);
else percent_right = math.floor(percent_right);
if(ie) document.all.floater_right.style.pixelleft += percent_right;
if(ns) document.floater_right.left += percent_right;
lastscrollx_right = lastscrollx_right + percent_right;
}
}
if(ns || ie) action = window.setinterval("heartbeat_right()",1);
function bigshow_right(){
document.all.div_right_250.style.visibility = 'visible';
document.all.div_right_80.style.visibility = 'hidden';
}
function bighide_right(){
document.all.div_right_80.style.visibility = 'visible';
document.all.div_right_250.style.visibility = 'hidden';
}document.write('');
document.write('');
document.write('');
把上面的代码另存为一个js文件,然后在想实现此效果的页面用<script type="text/javascript" language="javascript1.2" src="*.js"></script>调用即可,*代表你另存的文件名!注意修改广告图片地址和连接地址!