📄 softhouse_ad.js
字号:
/**
*软件屋 浮动广告js
*罗志威
*/
//x方向移动距离
var xposition=1;
//y方向移动距离
var yposition=1;
//滚动条离页面最顶的距离
var scrolltop;
//滚动条离页面最左的距离
var scrollleft;
//浮动广告对象数组
var objarray = new Array();
//左右广告对象数组
var bsobjarray = new Array();
//移动广告标志
var movePosflag=0;
//声名广告对象函数
function FlowAdvertisement(picUrl,httpUrl,altinfo,picWidth,picHeigth,xPosition,yPosition,speed)
{
this.picUrl = picUrl;
this.httpUrl = httpUrl;
this.altinfo = altinfo;
this.picWidth = picWidth;
this.picHeigth = picHeigth;
this.speed = speed;
this.xPosition = xPosition;
this.yPosition = yPosition;
this.layerid = guid();
this.xflag=true;
this.yflag = true;
this.moveflag = true;
var temp = this.layerid.substr(3);
objarray[temp-1] = this;
writeLayer(this);
initAd(this);
MoveLayer(objarray);
}
//页面左右两边的广告
function BothSidesAD(picUrl,httpUrl,altinfo,picWidth,picHeigth,xPosition,yPosition,BSMoveFlag)
{
// alert(window.document.documentElement.offsetWidth);
//alert(window.document.documentElement.scrollLeft);
this.position_flag = xPosition;
if(xPosition=="L")
xPosition = window.document.documentElement.scrollLeft+10;
else if (xPosition =="R")
xPosition = window.document.documentElement.offsetWidth - picWidth -10+window.document.documentElement.scrollLeft;
this.picUrl = picUrl;
this.httpUrl = httpUrl;
this.altinfo = altinfo;
this.picWidth = picWidth;
this.picHeigth = picHeigth;
this.BSMoveFlag = BSMoveFlag;
this.xPosition = xPosition;
if(parseInt(yPosition)>window.innerHeight-parseInt(picHeigth))
{
yPosition = window.document.documentElement.offsetHeight-parseInt(picHeigth)
yPosition = yPosition/2;
}
// alert(yPosition);
this.yPosition = yPosition;
this.layerid = gubsid();
writeBSLayer(this);
var temp = this.layerid.substr(3);
bsobjarray[temp-1] = this
initAd(this);
}
//将左右广告层的代码写入页面,其中包括广告图片,大小,连接
function writeBSLayer(obj)
{
var layer="<div id='"+obj.layerid+"' style='position:absolute; width:61px; height:59px; top: 0; left: 0; z-index:20; visibility:visible;' > ";
layer +="<a href='"+obj.httpUrl+"' target='_blank'><img src='"+obj.picUrl+"' border='0' height='"+obj.picHeigth+"' width='"+obj.picWidth+"' alt='"+obj.altinfo+"'></a></div>";
// layer+="<script LANGUAGE='JavaScript'>window.onscroll=moveBSAD;window.onresize=moveBSAD;window.onload=moveBSAD;</script>"
layer+="<script LANGUAGE='JavaScript'>window.onscroll=moveBSAD;window.onresize=moveBSAD;</script>"
moveBSAD();
document.write(layer);
}
function moveBSAD()
{
for(var i=0;i<bsobjarray.length;i++)
{
var temp = bsobjarray[i];
if(temp.BSMoveFlag=="yes")
{
var y_position = parseInt(temp.yPosition)+parseInt(window.document.documentElement.scrollTop);
if(navigator.appName == "Microsoft Internet Explorer")
{
if(y_position>window.document.documentElement.offsetHeight+document.documentElement.scrollTop-temp.picHeigth)
y_position = window.document.documentElement.offsetHeight+document.documentElement.scrollTop - temp.picHeigth-10;
// alert( window.document.documentElement.scrollTop +"==="+temp.yPosition);
}
else
{
if(y_position>window.innerHeight+document.documentElement.scrollTop-temp.picHeigth)
y_position = window.innerHeight+document.documentElement.scrollTop - temp.picHeigth-10;
}
eval("document.getElementById('"+temp.layerid+"').style.top="+y_position);
var x_position;
if(temp.position_flag=="L")
x_position = window.document.documentElement.scrollLeft+10;
else if (temp.position_flag =="R")
{
if(navigator.appName == "Microsoft Internet Explorer")
x_position = window.document.documentElement.offsetWidth - parseInt(temp.picWidth) -32+window.document.documentElement.scrollLeft;
else
x_position = window.document.documentElement.offsetWidth - parseInt(temp.picWidth) +window.document.documentElement.scrollLeft+parseInt(7);
}
eval("document.getElementById('"+temp.layerid+"').style.left="+x_position);
}
else
{
var x_position;
if(temp.position_flag=="L")
x_position = window.document.documentElement.scrollLeft+10;
else if (temp.position_flag =="R")
{
if(navigator.appName == "Microsoft Internet Explorer")
x_position = window.document.documentElement.offsetWidth - parseInt(temp.picWidth) -30+window.document.documentElement.scrollLeft;
else
x_position = window.document.documentElement.offsetWidth - parseInt(temp.picWidth) +window.document.documentElement.scrollLeft+parseInt(7);
}
eval("document.getElementById('"+temp.layerid+"').style.left="+x_position);
}
}
}
//将广告层的代码写入页面,其中包括广告图片,大小,连接
function writeLayer(obj)
{
var layer="<div id='"+obj.layerid+"' style='position:absolute; width:61px; height:59px; top:0mm; left:0mm; z-index:20px; visibility:hidden;' onMouseOver=stopmove('"+obj.layerid+"'); onMouseOut=start('"+obj.layerid+"'); > ";
layer +="<a href='"+obj.httpUrl+"' target='_blank'><img src='"+obj.picUrl+"' border='0' height='"+obj.picHeigth+"' width='"+obj.picWidth+"' alt='"+obj.altinfo+"'></a></div>";
document.write(layer);
}
//将某个广告停止移动
function stopmove(obj)
{
for(var i=0;i<objarray.length;i++)
{
if(objarray[i].layerid==obj)
{
objarray[i].moveflag = false;
break
}
}
}
//将停止移动的广告回复移动
function start(obj)
{
for(var i=0;i<objarray.length;i++)
{
if(objarray[i].layerid==obj)
{
objarray[i].moveflag = true;
break
}
}
}
//初始化某个广告层,主要设置初始位置
function initAd(obj)
{
// alert(window.document.documentElement.offsetHeight);
// alert(window.document.documentElement.offsetHeight);
scrolltop = window.document.documentElement.scrollTop;
scrollleft =window.document.documentElement.scrollLeft;
var temp = parseInt(scrolltop) +parseInt(obj.yPosition);
eval("document.getElementById('"+obj.layerid+"').style.top ="+obj.yPosition);//设置onLoad事件激发以后,广告层相对于固定后的y方向位置
eval("document.getElementById('"+obj.layerid+"').style.visibility = 'visible'");//设置层为可见
var temp = parseInt(scrollleft) + parseInt(obj.xPosition);
eval("document.getElementById('"+obj.layerid+"').style.left="+obj.xPosition);
}
//广告移动
function MoveLayer(objarray)
{
//根据移动广告标志来移动广告对象数组中的某个广告对象
var obj;
obj = objarray[movePosflag];
//下次调用移动下一个广告
movePosflag++;
//判断移动广告标志是否大于广告对象个数
movePosflag =movePosflag%objarray.length;
//判断该广告对象是否可移动
try
{
if(obj.moveflag==true)
{
//滚动条离页面最顶的距离
scrolltop = window.document.documentElement.scrollTop;
//滚动条离页面最左的距离
scrollleft =window.document.documentElement.scrollLeft
//ie可见区域的最大宽度(由ie可见区域的宽度-图片宽度+滚动条离页面最左的距离-广告边界距离)
var docwidth;
if(navigator.appName == "Microsoft Internet Explorer")
docwidth = window.document.documentElement.offsetWidth - obj.picWidth+scrollleft-30;
else
docwidth = window.document.documentElement.offsetWidth - obj.picWidth+scrollleft+10;
//ie可见区域的最大高度
var docheight;
if(navigator.appName == "Microsoft Internet Explorer")
docheight = window.document.documentElement.offsetHeight - obj.picHeigth+scrolltop-5;
else
{
docheight = window.innerHeight + scrolltop - obj.picHeigth-5;
}
//广告当前的x位置
var adx = eval("document.getElementById('"+obj.layerid+"').style.left");
//广告当前的y位置
var ady = eval("document.getElementById('"+obj.layerid+"').style.top");
//alert(ady);
//判断当前的x位置是否大于ie最大宽度,如果大则向右移动
if(parseInt(adx)>parseInt(docwidth))
{
obj.xflag = false;
}
//判断当前的x位置是否小于等于滚动条离页面最左的距离,如果大则向左移动
if(parseInt(adx)<=parseInt(scrollleft))
{
obj.xflag = true;
}
//判断当前的y位置是否大于ie最大高度,如果大则向上移动
if(navigator.appName == "Microsoft Internet Explorer")
{
if(parseInt(ady)>=parseInt(docheight))
{
//alert(1);
obj.yflag = false;
}
//判断当前的y位置是否小于等于滚动条离页面最顶的距离,如果大则向下移动
else if(parseInt(ady)<=parseInt(scrolltop))
{
//alert(2);
obj.yflag = true;
}
}
else
{
if(parseInt(ady)>parseInt(docheight))
{
obj.yflag = false;
}
//判断当前的y位置是否小于等于滚动条离页面最顶的距离,如果大则向下移动
else if(parseInt(ady)<=parseInt(scrolltop))
{
obj.yflag = true;
}
}
if(obj.xflag==true)
{
adx = parseInt(adx) + parseInt(xposition);
//防止滚动条拖动,广告离开ie可视区域
if(parseInt(adx)<parseInt(scrollleft))
adx=parseInt(scrollleft)+parseInt(obj.xPosition)/2;
}
else
{
adx = parseInt(adx) - parseInt(xposition);
//防止滚动条拖动,广告离开ie可视区域
if(parseInt(adx)>parseInt(docwidth))
adx=parseInt(docwidth)-parseInt(obj.xPosition);
if(parseInt(adx)<0)
adx =0;
}
if(obj.yflag==true)
{
ady = parseInt(ady)+parseInt(yposition);
//防止滚动条拖动,广告离开ie可视区域
if(parseInt(ady)<= parseInt(scrolltop))
ady =parseInt(scrolltop)+parseInt(obj.yPosition)/2;
//alert("scrolltop==="+scrolltop+" ady==="+ady+" docheight==="+docheight+" yposition==="+yposition +" obj.yPosition=="+obj.yPosition);
}
else
{
ady = parseInt(ady) - parseInt(yposition);
//防止滚动条拖动,广告离开ie可视区域
if(parseInt(ady)>parseInt(docheight))
ady =parseInt(docheight)-parseInt(obj.yPosition);
if(ady<0)
ady =0;
}
//设置广告层位置
eval("document.getElementById('" + obj.layerid + "').style.top ="+ady);
eval("document.getElementById('" + obj.layerid + "').style.left = "+adx);
}
}
catch(ex)
{
// alert(ex.number+"\n"+ex.description);
}
setTimeout("MoveLayer(objarray);", objarray[0].speed);
}
//获得全局变量,最为广告对象id
function guid()
{
if (!window.__id) window.__id = 0;
++window.__id;
return "ad_"+window.__id;
}
//获得全局变量,最为广告对象id
function gubsid()
{
if (!window.__bsid) window.__bsid = 0;
++window.__bsid;
return "bs_"+window.__bsid;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -