随页面滚动的对联广告
随页面滚动的对联广告
JS代码如下:
<script language="JavaScript">
var delta=0.8;
var collection;
var closeB=false;
function floaters()
{
this.items= [];
this.addItem= function(id,x,y,content)
{ //向页面写入一个
document.write('
');
document.write(content+'
');
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); //调用函数play()
}
}
function play()
{
if(screen.width<=800 || closeB)
{
for(var i=0;i
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-206',80,'
');
theFloaters.addItem('followDiv2',6,80,'
');///在这里改为文字或图片!!!!
theFloaters.play();
//页面其他内容显示输出
for(var i=0;i<120;i++)
{
document.write("这里是页面内容!");
}
</script>
扩展阅读
相关阅读