会说话的哑巴 2006-9-5 10:55
对联图片广告代码(最好的程序)
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.dfeng.net target=_blank><img src=ad/doublead/right.gif width=100 height=554 border=0></a><br><br><img src=ad/doublead/close.gif onClick="closeBanner();">');
theFloaters.addItem('followDiv2',0,0,'<a onClick="closeBanner();" href=http://www.dfeng.net target=_blank><img src=ad/doublead/ad_ad.gif width=100 height=400 border=0 ></a><br><br><img src=ad/doublead/close.gif onClick="closeBanner();">');
theFloaters.play();
把上面的代码另存为一个JS文件,然后在想实现此效果的页面用 调用即可,*代表你另存的文件名!
程序代码:
<script type="text/javascript" language="javascript1.2" src="*.js"></SCRIPT>
会说话的哑巴 2006-9-5 11:22
function floaters() {
this.items = [];
this.addItem = function(id,x,y,src,url,width,height)
{
if(src.substring(src.length-4,src.length)==".swf")
{
var content='<embed src="'+src+'" quality="high" pluginspage="[url]http://www.macromedia.com/go/getflashplayer[/url]" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>';
}
else
{
var content='<a href="'+url+'" target="_blank"><img src="'+src+'" border="0"></a>';
}
if(f_canClose)content+='<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" bgcolor="#6B6B6B"><img src="/ad/close.gif" onClick="closeBanner(\''+id+'\');"></td></tr></table>';
document.write('<div id='+id+' style="z-index: 10; position: absolute;width:'+width+'px; height:60px;left:'+(typeof(x)=='string'?eval(x):x)+'px;top:'+(typeof(y)=='string'?eval(y):y)+'px">'+content+'</div>');
var newItem= {};
newItem.object= document.getElementById(id);
newItem.x= x;
newItem.y= y;
this.items[this.items.length]= newItem;
}
this.play = function()
{
f_collection= this.items
if(f_Isfloat)f_intervalId=setInterval('play()',1);
}
}
function play()
{
if(screen.width<=500 || f_closeB)
{
for(var i=0;i<f_collection.length;i++)
{
f_collection[i].object.style.display = 'none';
}
clearInterval(f_intervalId);
return;
}
var scrollLeft=document.body.scrollLeft;
if(scrollLeft==0)scrollLeft=document.documentElement.scrollLeft;//XHTML版本scrollLeft
var scrollTop=document.body.scrollTop;
if(scrollTop==0)scrollTop=document.documentElement.scrollTop;
for(var i=0;i<f_collection.length;i++)
{
var followObj= f_collection[i].object;
var followObj_x= (typeof(f_collection[i].x)=='string'?eval(f_collection[i].x):f_collection[i].x);
var followObj_y= (typeof(f_collection[i].y)=='string'?eval(f_collection[i].y):f_collection[i].y);
if(followObj.offsetLeft!=(scrollLeft+followObj_x)) {
var dx=(scrollLeft+followObj_x-followObj.offsetLeft)*f_delta;
dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
followObj.style.left=followObj.offsetLeft+dx;
}
if(followObj.offsetTop!=(scrollTop+followObj_y)) {
var dy=(scrollTop+followObj_y-followObj.offsetTop)*f_delta;
dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
followObj.style.top=followObj.offsetTop+dy;
}
}
}
function closeBanner(DivName)
{
for(var i=0;i<f_collection.length;i++)
{
if(f_IsCloseAll)
f_collection[i].object.style.display = 'none';
else
if(f_collection[i].object.id==DivName)f_collection[i].object.style.display = 'none';
}
if(f_Isfloat&&f_IsCloseAll)clearInterval(f_intervalId);
return;
}
var theFloaters= new floaters();
//theFloaters.addItem('DivName',x,y,'src',url,width,height);
theFloaters.addItem('followDiv1','Math.floor((document.body.clientWidth-755)/2-115)',115,'图片地址','链接地址',115,210);
theFloaters.addItem ('followDiv2','Math.floor(document.body.clientWidth-(document.body.clientWidth -755)/2)',115,'图片地址','链接地址',115,210);
theFloaters.play();
会说话的哑巴 2006-9-5 11:31
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.sightchina.com/html/china/ target=_blank><img src=/images/ok.gif width=100 height=239 border=0></a><br><img src=/images/close.gif onClick="closeBanner();">');
theFloaters.addItem('followDiv2',0,0,'<a onClick="closeBanner();" href=http://www.sightchina.com/html/state/newinfo/754.html target=_blank><img src=/images/ok1.gif width=100 height=239 border=0 ></a><br><img src=/images/close.gif onClick="closeBanner();">');
theFloaters.play();