2边浮动广告

本文介绍了一种使用JavaScript实现的网页两侧浮动广告效果的方法。通过判断广告类型(图片或Flash),动态生成相应的HTML代码,并利用setInterval进行滚动效果更新。此外,还提供了关闭浮动广告的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

2边浮动广告

把下面js放在一个ad.js的文件.直接<script language="javascript" src="ad.js"></script>就可以了
//1
var type=2;   //广告显示的类别,1图片,2falsh
 var left_ads="";  //左边广告
 var right_ads="";  //右边广告
 if(type==1){   //广告为图片
  left_ads="<a href='#' target='_blank'><img src='left.gif' width='95' height='300' border='0' alt='欢迎访问本站'></a>"
  right_ads="<a href='#' target='_blank'><img src='rig.gif' width='95' height='300' border='0' alt='欢迎访问本站'></a>"
 }
 else if(type==2){   //广告为flash
  left_ads=reloadfalsh('300','90','swf/ad_right.swf','yes');
  right_ads=reloadfalsh('300','90','swf/ad_right.swf','yes');
 }
 suspendcode="<DIV id=lovexin1 style='Z-INDEX: 10; LEFT: -0px; POSITION: absolute; TOP: 100px; width: 90; height: 203px;'>"+left_ads+"</DIV>"
 document.write(suspendcode);
 suspendcode="<DIV id=lovexin2 style='Z-INDEX: 10; right: 0px; POSITION: absolute; TOP: 100px; width: 90; height: 203px;'>"+right_ads+"</DIV>"
 document.write(suspendcode);
 lastScrollY=0;
 function heartBeat(){
 diffY=document.body.scrollTop;
 percent=.3*(diffY-lastScrollY);
 if(percent>0)percent=Math.ceil(percent);
 else percent=Math.floor(percent);
 document.all.lovexin1.style.pixelTop+=percent;
 document.all.lovexin2.style.pixelTop+=percent;
 lastScrollY=lastScrollY+percent;
 } 
 //关闭浮动广告
 function hide()
 {
 lovexin1.style.visibility="hidden";
 lovexin2.style.visibility="hidden";
 }
 //去掉flash的虚线框开始
 function reloadfalsh(height,width,url,transparent){
  var falshbl="";
  falshbl+="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0' width='"+width+"' height='"+height+"'>\n";
  falshbl+="<param name='movie' value='"+url+"' />\n";
  falshbl+="<param name='quality' value='high' />\n";
  if(transparent=="yes"){
   falshbl+="<param name='wmode' value='transparent' />\n";
  } 
  falshbl+="<embed src='"+url+"' quality='high' pluginspage='http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash' type='application/x-shockwave-flash' width='"+width+"' height='"+height+"'></embed>\n";
  falshbl+="</object>\n";
  return falshbl;
 }
 //去掉flash的虚线框结束
 window.setInterval("heartBeat()",1);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值