您现在的位置: 365建站网 > 365文章 > 浮动对联广告代码 兼容if,firefox

浮动对联广告代码 兼容if,firefox

文章来源:365jz.com     点击数:1119    更新时间:2010-12-29 20:15   参与评论

浮动对联广告代码 兼容if,firefox,因为offsetLeft在firefox中相加的数字需要加上px,如 followObj.style.left=followObj.offsetLeft+dx+"px";//没有加上px   Firefox就不可以显示

标红的为需要修改的代码:

<!--  Welcome to www.365jz.com. -->

var delta=0.8;
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.documentElement.scrollLeft+followObj_x)) {
var dx=(document.documentElement.scrollLeft+followObj_x-followObj.offsetLeft)*delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx+ "px";
////没有加上px   浮动窗口Firefox就不可以显示

}

if(followObj.offsetTop!=(document.documentElement.scrollTop+followObj_y)) {
var dy=(document.documentElement.scrollTop+followObj_y-followObj.offsetTop)*delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy+ "px";
////没有加上px   浮动窗口Firefox就不可以显示

}
followObj.style.display= '';
}
}
function closeBanner()
{
closeB=true;
return;
}

var theFloaters= new floaters();
theFloaters.addItem('followDiv1','document.documentElement.clientWidth-106',80,'这里加浮动的内容1');
theFloaters.addItem('followDiv2',6,80,'这里加浮动的内容2');
theFloaters.play();

 1.此浮动对联广告在有没有<!DOCTYPE html 的网页里表现形式是不一样的:
    <!DOCTYPE html 有的情况下是: document.documentElement.
    <!DOCTYPE html 没有的情况下是: document.body.
2.如果要兼容if,firefox如果修改:
    followObj.style.left=followObj.offsetLeft+dx+ "px";
    ////没有加上px   浮动窗口Firefox就不可以显示
    followObj.style.top=followObj.offsetTop+dy+ "px";
    ////没有加上px   浮动窗口Firefox就不可以显示

如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛

您可能感兴趣的文章:

发表评论 (1119人查看0条评论)
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
昵称:
最新评论
------分隔线----------------------------

快速入口

· 365软件
· 杰创官网
· 建站工具
· 网站大全

其它栏目

· 建站教程
· 365学习

业务咨询

· 技术支持
· 服务时间:9:00-18:00
365建站网二维码

Powered by 365建站网 RSS地图 HTML地图

copyright © 2013-2024 版权所有 鄂ICP备17013400号