查看完整版本: 对联图片广告代码(最好的程序)

会说话的哑巴 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(&#39;<DIV id=&#39;+id+&#39; style="Z-INDEX: 10; POSITION: absolute;  width:80px; height:60px;left:&#39;+(typeof(x)==&#39;string&#39;?eval(x):x)+&#39;;top:&#39;+(typeof(y)==&#39;string&#39;?eval(y):y)+&#39;">&#39;+content+&#39;</DIV>&#39;);
   
    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(&#39;play()&#39;,30);
    }
  }
  function play()
  {
  if(screen.width<=800 || closeB)
  {
   for(var i=0;i<collection.length;i++)
   {
    collection[i].object.style.display = &#39;none&#39;;
   }
   return;
  }
  for(var i=0;i<collection.length;i++)
  {
   var followObj  = collection[i].object;
   var followObj_x  = (typeof(collection[i].x)==&#39;string&#39;?eval(collection[i].x):collection[i].x);
   var followObj_y  = (typeof(collection[i].y)==&#39;string&#39;?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 = &#39;&#39;;
  }
  }
  function closeBanner()
  {
  closeB=true;
  return;
  }

var theFloaters  = new floaters();
//
theFloaters.addItem(&#39;followDiv1&#39;,&#39;document.body.clientWidth-100&#39;,0,&#39;<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();">&#39;);
theFloaters.addItem(&#39;followDiv2&#39;,0,0,&#39;<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();">&#39;);
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=&#39;<embed src="&#39;+src+&#39;" quality="high" pluginspage="[url]http://www.macromedia.com/go/getflashplayer[/url]" type="application/x-shockwave-flash" width="&#39;+width+&#39;" height="&#39;+height+&#39;"></embed>&#39;;
   }
   else
   {
    var content=&#39;<a href="&#39;+url+&#39;" target="_blank"><img src="&#39;+src+&#39;" border="0"></a>&#39;;
   }
   if(f_canClose)content+=&#39;<table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="right" bgcolor="#6B6B6B"><img src="/ad/close.gif" onClick="closeBanner(\&#39;&#39;+id+&#39;\&#39;);"></td></tr></table>&#39;;
   document.write(&#39;<div id=&#39;+id+&#39; style="z-index: 10; position: absolute;width:&#39;+width+&#39;px; height:60px;left:&#39;+(typeof(x)==&#39;string&#39;?eval(x):x)+&#39;px;top:&#39;+(typeof(y)==&#39;string&#39;?eval(y):y)+&#39;px">&#39;+content+&#39;</div>&#39;);
  
   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(&#39;play()&#39;,1);
  }
  }
  function play()
  {
   if(screen.width<=500 || f_closeB)
   {
    for(var i=0;i<f_collection.length;i++)
    {
      f_collection[i].object.style.display = &#39;none&#39;;
    }
    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)==&#39;string&#39;?eval(f_collection[i].x):f_collection[i].x);
    var followObj_y= (typeof(f_collection[i].y)==&#39;string&#39;?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 = &#39;none&#39;;
   else
    if(f_collection[i].object.id==DivName)f_collection[i].object.style.display = &#39;none&#39;;
  }
  if(f_Isfloat&&f_IsCloseAll)clearInterval(f_intervalId);
  return;
}

var theFloaters= new floaters();

//theFloaters.addItem(&#39;DivName&#39;,x,y,&#39;src&#39;,url,width,height);
theFloaters.addItem(&#39;followDiv1&#39;,&#39;Math.floor((document.body.clientWidth-755)/2-115)&#39;,115,&#39;图片地址&#39;,&#39;链接地址&#39;,115,210);
theFloaters.addItem (&#39;followDiv2&#39;,&#39;Math.floor(document.body.clientWidth-(document.body.clientWidth -755)/2)&#39;,115,&#39;图片地址&#39;,&#39;链接地址&#39;,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(&#39;<DIV id=&#39;+id+&#39; style="Z-INDEX: 10; POSITION: absolute;  width:80px; height:60px;left:&#39;+(typeof(x)==&#39;string&#39;?eval(x):x)+&#39;;top:&#39;+(typeof(y)==&#39;string&#39;?eval(y):y)+&#39;">&#39;+content+&#39;</DIV>&#39;);
   
    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(&#39;play()&#39;,30);
    }
  }
  function play()
  {
  if(screen.width<=800 || closeB)
  {
   for(var i=0;i<collection.length;i++)
   {
    collection[i].object.style.display = &#39;none&#39;;
   }
   return;
  }
  for(var i=0;i<collection.length;i++)
  {
   var followObj  = collection[i].object;
   var followObj_x  = (typeof(collection[i].x)==&#39;string&#39;?eval(collection[i].x):collection[i].x);
   var followObj_y  = (typeof(collection[i].y)==&#39;string&#39;?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 = &#39;&#39;;
  }
  }
  function closeBanner()
  {
  closeB=true;
  return;
  }

var theFloaters  = new floaters();
//
theFloaters.addItem(&#39;followDiv1&#39;,&#39;document.body.clientWidth-100&#39;,0,&#39;<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();">&#39;);
theFloaters.addItem(&#39;followDiv2&#39;,0,0,&#39;<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();">&#39;);
theFloaters.play();

梦凡 2006-9-13 19:48

怎么这么长呀!我没仔细看过,效果好吗》??

风云际 2006-9-20 09:41

很好用的!
页: [1]
查看完整版本: 对联图片广告代码(最好的程序)
baidu
互联网 www.ymxd.net