兼容多浏览器右下角浮动广告js代码
兼容多浏览器右下角浮动广告js代码
var opp;
var wh;
var hi;
var dialogright = function(title,content,height,width)
{
var my = this;
this._title = title;
this._content = content;
this._height = height;
hi = height;
this._width = width;
wh = width;
this._time = 5;
this._timer = null;
this.div_name = "";
this.show = function()
{
var date = new date();
var divname = "";
divname += new string(date.getmilliseconds());
divname += math.random(0)*10;
divname = divname.replace(".","_");
my.div_name = divname;
opp = document.createelement("div");
opp.id = divname;
opp.style.position = "absolute";
//opp.style.border = "solid 1px #000";
opp.style.width = my._width + "px";
opp.style.height = 10 + "px"//慢慢延伸到my._height高度;
opp.style.overflow = "hidden";
opp.style.zindex = 9999;
var left = document.documentelement.clientwidth - my._width ;
var top = document.documentelement.scrolltop + document.documentelement.clientheight - 10;
opp.style.left = left - 5 + "px";
opp.style.top = top + "px";
var html = "<div style='position:absolute;width:6%;background:#ededed;border:1px slide #cdcdcd;right:2px;top:8px;text-align:center;font-weight:bold;'><a href='网页特效:;' onclick='closeo教程pp("" + divname + "")' ><img src="http://www.haofz.com/images/gb.jpg"></a></div>";
html += "<div style='height:230px;overflow:hidden;font-size:12px;padding:4px;clear:both'><a href='http://www.haofjj.com/activity/activity.asp教程x?id=8' target='_blank'><img src='/upload/20130916/2010/03/20110305005225747.jpg' border='0' /></a><div>"
/*
var html = "<iframe src='http://www.zhutiai.com' width='295px' height='230px' frameborder='0' scrolling='no'></iframe>"
html += "<div style='position:absolute;width:6%;background:#ededed;border:1px slide #cdcdcd;right:2px;top:8px;text-align:center;font-weight:bold;'><a href='javascript:;' onclick='closeopp("" + divname + "")' ><img src="http://www.haofz.com/images/gb.jpg"></a></div>";
html += "<div style='filter:alpha(opacity=10);-moz-opacity:1.0;opacity:1.0;float:right;position:absolute;width:13%;right:12px;top:6px;background:red' onclick='closeopp("" + divname + "")'> </div>";
*/
//opp.innerhtml = "";//隐藏
opp.innerhtml = html;//显示
if(dialogright.prototype.alldivname == "" || dialogright.prototype.alldivname == undefined)
dialogright.prototype.alldivname = divname;
else
dialogright.prototype.alldivname += "|" + divname;
document.body.appendchild(opp);
my.render();
}
this.render = function()
{
if(my._timer == null)
{
my._timer = setinterval(my.expand,my._time);
}
}
this.expand = function()
{
var _obj = document.getelementbyid(my.div_name);
var tp = _obj.style.top;
if(window.navigator.appname == "netscape" ? parseint(tp.replace("px","")) >= document.documentelement.clientheight - my._height : _obj.clientheight <= my._height)
{
var hi = _obj.style.height;
hi = parseint(hi.replace("px",""));
tp = parseint(tp.replace("px",""));
_obj.style.height = hi + 2;
_obj.style.top = (tp - 2) + "px";
}
else
{
clearinterval(my._timer);
}
}
}
dialogright.prototype.removedivname = function(divname)
{
var divname = dialogright.prototype.alldivname;
divname = divname.replace(divname,"");
divname = divname.replace("|"+divname ,"");
dialogright.prototype.alldivname = divname;
}
function closeopp(divname)
{
var obj = document.getelementbyid(divname);
document.body.removechild(obj);
dialogright.prototype.removedivname(divname);
}
window.onscroll = function ()//滚动时保持原相对位置
{
var divnames = dialogright.prototype.alldivname == undefined ? "" : dialogright.prototype.alldivname;
if(divnames != "")
{
var divname = divnames.split("|");
for(var i=0;i<divname.length;i++)
{
var obj = document.getelementbyid(divname[i]);
if(obj != null){
if(window.navigator.appname == "netscape")
obj.style.top = document.documentelement.scrolltop + document.documentelement.clientheight - hi + "px";
else
obj.style.top = document.documentelement.scrolltop + document.documentelement.clientheight - obj.clientheight + "px";
}
}
}
}
function kleft(){
var left = document.documentelement.clientwidth - wh ;
opp.style.left = left - 5 + "px";
//alert(left);
}
var test2 = new dialogright("","",240,295);
test2.show();
setinterval('kleft()',100);
补充:网页制作,js教程