帮我给这段js对联图片浮动广告的代码增加关闭按钮
这是js:vardelta=0.08varcollection;functionfloaters(){this.items=[];this.addItem=functio...
这是js:
var delta=0.08
var collection;
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()',10);
}
}
function play()
{
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 = '';
}
}
var theFloaters = new floaters();
//右面
theFloaters.addItem('followDiv1','document.body.clientWidth-106',80,'<a href=/index.asp target=_blank><img src=logo1.gif border=0></a>');
//左面
theFloaters.addItem('followDiv2',6,80,'<a href=/index.asp target=_blank><img src=logo2.gif border=0></a>');
theFloaters.play();
因为我的对联图片比较大,低分辨率浏览可能要遮挡内容,所以希望增加关闭按钮,好的话追加分,谢啦~ 展开
var delta=0.08
var collection;
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()',10);
}
}
function play()
{
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 = '';
}
}
var theFloaters = new floaters();
//右面
theFloaters.addItem('followDiv1','document.body.clientWidth-106',80,'<a href=/index.asp target=_blank><img src=logo1.gif border=0></a>');
//左面
theFloaters.addItem('followDiv2',6,80,'<a href=/index.asp target=_blank><img src=logo2.gif border=0></a>');
theFloaters.play();
因为我的对联图片比较大,低分辨率浏览可能要遮挡内容,所以希望增加关闭按钮,好的话追加分,谢啦~ 展开
2个回答
展开全部
把 theFloaters.addItem .... 这两个 修改一下, 在里面添加
<div style="text-align:right;"><span onclick="document.getElementById(\'followDiv1\').style.display=\'none\'">X</span></div>
重要的是 onclick="document.getElementById(\'followDiv1\').style.display=\'none\'" 这个不能少,你想要哪个点击关闭就把这个放到哪个HTML标签里面, 其它的可以根据自己需要修改美化一下
改成
theFloaters.addItem('followDiv1','document.body.clientWidth-106',80,'<div style="text-align:right;"><span onclick="document.getElementById(\'followDiv1\').style.display=\'none\'">X</span></div><a href=/index.asp target=_blank><img src=logo1.gif border=0></a>');
//左面
theFloaters.addItem('followDiv2',6,80,'<div style="text-align:right;"><span onclick="document.getElementById(\'followDiv1\').style.display=\'none\'">X</span></div><a href=/index.asp target=_blank><img src=logo2.gif border=0></a>');
<div style="text-align:right;"><span onclick="document.getElementById(\'followDiv1\').style.display=\'none\'">X</span></div>
重要的是 onclick="document.getElementById(\'followDiv1\').style.display=\'none\'" 这个不能少,你想要哪个点击关闭就把这个放到哪个HTML标签里面, 其它的可以根据自己需要修改美化一下
改成
theFloaters.addItem('followDiv1','document.body.clientWidth-106',80,'<div style="text-align:right;"><span onclick="document.getElementById(\'followDiv1\').style.display=\'none\'">X</span></div><a href=/index.asp target=_blank><img src=logo1.gif border=0></a>');
//左面
theFloaters.addItem('followDiv2',6,80,'<div style="text-align:right;"><span onclick="document.getElementById(\'followDiv1\').style.display=\'none\'">X</span></div><a href=/index.asp target=_blank><img src=logo2.gif border=0></a>');
展开全部
<DIV id='+id+' style="Z-INDEX: 10; POSITION: absolute; width:80px; overflow:heidden; left:'+(typeof(x)=='string'?eval(x):x)+';top:'+(typeof(y)=='string'?eval(y):y)+'"><a href="javascript:void(0);" style="float:left;display:block;width:16px; height:16px;border:1px solid #000;" onclick="this.parentElement.style.display=\'none\';return;">×</a>'+content+'</DIV>
你把第一个document.write改了就行了!
你把第一个document.write改了就行了!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询