JS对联漂浮广告

javascript

2008-08-27 10:14

调用:<script src="inc/smsline_double.js"></script>

-------------------------------------------------------------------------------------
smsline_double.js
// common
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}

// 关闭广告(提供给flash使用的关闭接口)
function closead(){
closeNum=2;//设定关闭广告的数量,1-只关闭本身;2-同时关闭全部
if(closeNum==1){
document.activeElement.parentNode.style.visibility= 'hidden'; //仅当广告类型为flash时在IE下有效,firefox下将不会关闭任何广告
}
if(closeNum==2){//可以兼容firefox
MM_showHideLayers("leftad","","hide");
MM_showHideLayers("rightad","","hide");
}
}
//-->

//浏览器窗口参数定义及获取函数,兼容IE6&MF by nokersang *
var theX; //浏览器窗口宽度
if(document.documentElement.clientWidth<document.body.clientWidth&&document.documentElement.clientWidth){
theX = 'document.documentElement.clientWidth';
}else{
theX = 'document.body.clientWidth';
}

var theY; //浏览器窗口高度
if(document.documentElement.clientHeight<=document.body.clientHeight&&document.documentElement.clientHeight){
theY = 'document.documentElement.clientHeight';
}else{
theY = 'document.body.clientHeight';
}

function scrollTop() //浏览器滚动条位置
{
var scrollTop;
if (document.documentElement && document.documentElement.scrollTop){
scrollTop = document.documentElement.scrollTop;
}else if (document.body){
scrollTop = document.body.scrollTop;
}else if (window.pageYOffset){
scrollTop = window.pageYOffset;
}
return scrollTop;
}

// 参数设置,包括广告显示数量、广告文件的规格、类型、地址和广告边距,左右可使用不同设置,如果设置了不显示某侧广告那么该广告的所有参数设置都无效
var delta=0.075;
var collection,right_ad,left_ad,LeftAd_Type,RighAd_Type;

if(contentWidth == null)//判断参数contentWidth是否存在,便于接受页面参数为不同内容宽度页面定制浮动 by nokersang
{
var contentWidth=752;//页面内容区域宽度,建议使用4的整数倍
}
var maxHeight=410;//定义可见的浮动内容最下沿距浏览器窗口内容部分顶端的高度,建议留几像素余地

var display="both"//设定广告显示数量。left:只显示左侧;right:只显示右侧;both:全部显示;none:全部关闭

var LeftAd_Type="pic";//设定左侧广告类型,swf:flash文件;pic:jpg或gif文件
var LeftAd_Dime="d"//设定左侧广告规格。d:对联类 100*300;f:浮标类 80*80
var LeftAd_Url="images/1.gif";//设定左广告文件的地址
var LeftAd_link="/news.asp?id=1604"; //设置左侧广告的跳转连接地址(flash无须设置)
var LeftAd_top=80;//设定左广告top边距(常规情况无需更改)
var LeftAd_left=eval(theX)<=(contentWidth+200)?0:Math.round((eval(theX)-contentWidth)*0.25-50);//设定左广告left边距,浮动在内容之外空间上自动居中 by nokersang

var RightAd_Type="pic";//设定右侧广告类型,swf:flash文件;pic:jpg或gif文件
var RightAd_Dime="d"//设定右侧广告规格。d:对联类 100*300;f:浮标类 80*80
var RightAd_Url="images/2.gif";//设定右广告文件的地址
var RightAd_link="news.asp?id=1603"; //设置右侧广告的跳转连接地址(flash无须设置)
var RightAd_top=80;//设定右广告top边距(常规情况无需更改)
var RightAd_left=eval(theX)>(contentWidth+200)?Math.round(eval(theX)*0.75+contentWidth*0.25-50):Math.round(screen.width*0.75+125);//设定右广告left边距,浮动在内容之外空间上自动居中 by nokersang

// "返回顶部"的设置
var ifGoTop="y";//是否出现“返回顶部”。y:出现;n:隐藏

//以下代码无须改动
var gotop="<table width=100 border=0 cellpadding=0 cellspacing=0> <tr> <td><a onClick=\"javascript:window.scroll(0,0);return false;\" style=\"cursor:pointer\"><img src=http://sms.qq.com/images2005/bt_gotop.gif width=18 height=18 border=0 /></a></td> <td><a onClick=\"javascript:window.scroll(0,0);return false;\" style=\"cursor:pointer\" onmouseover=\'this.style.color=\"#AAA\"\' onmouseout=\'this.style.color=\"#000\"\'>返回页顶</a></td></tr></table>"// 对联返回改为js方式 by jornnyliu
if (LeftAd_Type=="pic"&&LeftAd_Dime=="d"){
left_ad="<table width=100 border=0 cellspacing=0 cellpadding=0><tr><td height=24 background=http://sms.qq.com/images2005/pub_double_close.gif align=right><img src=http://sms.qq.com/images2005/bt_double_closead.gif width=22 border=0 onclick=\"javascript:closead();return false\" style=\"cursor:pointer\"/></td> </tr> <tr> <td height=276 align=center valign=middle background=http://sms.qq.com/images2005/pub_double_bg.gif><a href="+LeftAd_link+" target=_blank><img src="+LeftAd_Url+" width=90 height=267 border=0 /></a></td> </tr> </table>";
}
if (LeftAd_Type=="pic"&&LeftAd_Dime=="f"){
left_ad="<a href="+LeftAd_link+" target=_blank><img src="+LeftAd_Url+" width=80 height=80 border=0 /></a>";
}
if (RightAd_Type=="pic"&&RightAd_Dime=="d"){
right_ad="<table width=100 border=0 cellspacing=0 cellpadding=0> <tr> <td height=24 background=http://sms.qq.com/images2005/pub_double_close.gif align=right><img src=http://sms.qq.com/images2005/bt_double_closead.gif width=22 border=0 onclick=\"javascript:closead();return false\" style=\"cursor:pointer\"/></td> </tr> <tr> <td height=276 align=center valign=middle background=http://sms.qq.com/images2005/pub_double_bg.gif><a href="+RightAd_link+" target=_blank><img src="+RightAd_Url+" width=90 height=267 border=0 /></a></td> </tr> </table>"
}
if (RightAd_Type=="pic"&&RightAd_Dime=="f"){
right_ad="<a href="+RightAd_link+" target=_blank><img src="+RightAd_Url+" width=80 height=80 border=0 /></a>";
}
if (LeftAd_Type=="swf"&&LeftAd_Dime=="d"){
left_ad="<object id=flashad classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\" width=\"100\" height=\"300\"> <param name=\"movie\" value=\""+LeftAd_Url+"\" /> <param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\""+LeftAd_Url+"\" width=\"100\" height=\"300\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed> </object>";
}
if (LeftAd_Type=="swf"&&LeftAd_Dime=="f"){
left_ad="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\" width=\"80\" height=\"80\"> <param name=\"movie\" value=\""+LeftAd_Url+"\" /> <param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\""+LeftAd_Url+"\" width=\"80\" height=\"80\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed> </object>";
}
if (RightAd_Type=="swf"&&RightAd_Dime=="d"){
right_ad="<object id=flashad classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\" width=\"100\" height=\"300\"> <param name=\"movie\" value=\""+RightAd_Url+"\" /> <param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\""+RightAd_Url+"\" width=\"100\" height=\"300\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed> </object>";
}
if (RightAd_Type=="swf"&&RightAd_Dime=="f"){
right_ad="<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab\" width=\"80\" height=\"80\"> <param name=\"movie\" value=\""+RightAd_Url+"\" /> <param name=\"quality\" value=\"high\" /><param name=\"wmode\" value=\"transparent\" /><embed src=\""+RightAd_Url+"\" width=\"80\" height=\"80\" quality=\"high\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" type=\"application/x-shockwave-flash\"></embed> </object>";
}

function floaters() {
this.items = [];
this.addItem = function(id,x,y,content){
var str = '<DIV id='+id+' style="Z-INDEX:10; POSITION: absolute;display:block;left:'+(typeof(x)=='string'?eval(x):x)+'px;top:'+(typeof(y)=='string'?eval(y):y)+'px">'+content+'</DIV>';
document.write(str);

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(){
//动态根据窗口大小判断隐藏 by nokersang
if(eval(theX)<parseInt(contentWidth+200)||eval(theY)<maxHeight){
for(var i=0;i<collection.length;i++)
   {
   collection[i].x=(collection[i].object.offsetLeft?collection[i].object.offsetLeft:collection[i].x);//MF层位置保存,兼容代码 nokersang
   collection[i].object.style.display="none";
   }
}else{
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(collection[i].object.style.display!="block"){
    followObj.style.left=followObj_x+"px" //MF层位置获取,兼容代码 nokersang
    collection[i].object.style.display="block";
   }
   //左右浮动区别处理动态处理代码,动态浮动,解决窗口水平变小时Flash跳动及短时间出现水平滚动条问题 by nokersang *
   if(i==0&&display!="right"){
    if(followObj.offsetLeft!=Math.round((eval(theX)-contentWidth)*0.25-50)){
    var dx=((eval(theX)-contentWidth)*0.25-50-followObj.offsetLeft)*delta;
    dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
    followObj.style.left=followObj.offsetLeft+dx+"px";
    }
   }else{
    if(followObj.offsetLeft!=Math.round(eval(theX)*0.75+contentWidth*0.25-50)){
    var dx=(Math.ceil(eval(theX)*0.75+contentWidth*0.25-50)-followObj.offsetLeft);
    dx=(dx<0&&(followObj.offsetLeft+100)>eval(theX)?dx:dx*delta);
    dx=(dx>0?1:-1)*Math.ceil(Math.abs(dx));
    followObj.style.left=followObj.offsetLeft+dx+"px";
    }
   }
   if(followObj.offsetTop!=(scrollTop()+followObj_y)) {
    var dy=(scrollTop()+followObj_y-followObj.offsetTop)*delta;
    dy=(dy>0?1:-1)*Math.ceil(Math.abs(dy));
    followObj.style.top=followObj.offsetTop+dy+"px";
   }
   collection[i].object.style.display="block";
}
}
} 
    
var theFloaters = new floaters();

if (display=="both"){
theFloaters.addItem('leftad',LeftAd_left,LeftAd_top,left_ad);
theFloaters.addItem('rightad',RightAd_left,RightAd_top,right_ad);
}
if (display=="left"){
theFloaters.addItem('leftad',LeftAd_left,LeftAd_top,left_ad);
}
if (display=="right"){
theFloaters.addItem('rightad',RightAd_left,RightAd_top,right_ad);
}
if (ifGoTop=="y"){
theFloaters.addItem('gotop',RightAd_left,390,gotop);
}
theFloaters.play();

document.write("<SCRIPT language=JavaScript event=FSCommand() for=flashad> leftad.style.visibility='hidden'; rightad.style.visibility='hidden'; </SCRIPT>");

// JavaScript Document