1 function lsFloat(id,location,intervalshow){
2 this.ID=id;
3 this.InnerHTML="";
4 this.Location=location;
5 this.IntervalShow=intervalshow;
6 this.CloseButton=true;
7 this.Width=0;
8 this.Height=0;
9 this.IE6CalibrationlsTop=6;//校准IE6偏差
10 }
11 ///关闭浮动
12 function lsFloatClose(ID,Time){
13 document.getElementById(ID).style.display="none";
14 setTimeout(function(){
15 document.getElementById(ID).style.display="block";
16 },Time);
17 }
18 ///校准位置
19 function CalibrationlsFloatOffset(ID,Location){
20 var Obj=document.getElementById(ID);
21 switch(Location.toLowerCase()){
22 case "left"://左居中
23 Obj.style.top=GetFloatOffsetTop(Obj.clientHeight);
24 break;
25 case "right"://右居中
26 Obj.style.top=GetFloatOffsetTop(Obj.clientHeight);
27 break;
28 case "centent"://居中
29 Obj.style.left=GetFloatOffsetLeft(parseInt(Obj.style.width));
30 Obj.style.top=GetFloatOffsetTop(parseInt(Obj.style.height));
31 break;
32 }
33 }
34 ///校准位置
35 function _CalibrationlsFloatOffset(ID,Location,IE6CalibrationlsTop){
36 var Obj=document.getElementById(ID);
37 switch(Location.toLowerCase()){
38 case "left"://左居中
39 Obj.style.setExpression("top","eval(document.documentElement.scrollTop+"+GetFloatOffsetTop(parseInt(Obj.style.height))+")");
40 break;
41 case "right"://右居中
42 Obj.style.setExpression("top","eval(document.documentElement.scrollTop+"+GetFloatOffsetTop(parseInt(Obj.style.height))+")");
43 break;
44 case "lefttop"://左上
45 Obj.style.setExpression("top","eval(document.documentElement.scrollTop)");
46 break;
47 case "righttop"://右上
48 Obj.style.setExpression("top","eval(document.documentElement.scrollTop)");
49 break;
50 case "leftbottom"://左下
51 Obj.style.setExpression("top","eval(document.documentElement.scrollTop+"+document.documentElement.clientHeight+"-"+(parseInt(Obj.style.height)+IE6CalibrationlsTop)+")");
52 break;
53 case "rightbottom"://右下
54 Obj.style.setExpression("top","eval(document.documentElement.scrollTop+"+document.documentElement.clientHeight+"-"+(parseInt(Obj.style.height)+IE6CalibrationlsTop)+")");
55 break;
56 case "centent"://居中
57 Obj.style.setExpression("top","eval(document.documentElement.scrollTop+"+GetFloatOffsetTop(parseInt(Obj.style.height))+")");
58 Obj.style.setExpression("left","eval(document.documentElement.scrollLeft+"+GetFloatOffsetLeft(parseInt(Obj.style.width))+")");
59 break;
60 }
61 }
62 ///返回绝对位置
63 //return OffseTop
64 function GetFloatOffsetTop(Height){
65 var clentHeight=document.documentElement.clientHeight;
66 var offsettop=0;
67 offsettop=clentHeight/2-Height/2;
68 return parseInt(offsettop);
69 }
70
71 //return OffseLeft
72 function GetFloatOffsetLeft(Width){
73 var clentWidth=document.documentElement.clientWidth;
74 var offsetleft=0;
75 offsetleft=clentWidth/2-Width/2;
76 return parseInt(offsetleft);
77 }
78 ///返回浏览器版本
79 lsFloat.prototype.GetBrowserVersion=function(){
80 var browser=navigator.appName;
81 var b_version=navigator.appVersion;
82 var version=b_version.split(";");
83 var trim_Version=version[1].replace(/[ ]/g,"");
84
85 if(browser=="Microsoft Internet Explorer"){
86 if(trim_Version=="MSIE6.0"){
87 return "IE6";
88 }else{
89 return "IE6+";
90 }
91 }else{
92 return "NotIE";
93 }
94 }
95 //返回样式
96 lsFloat.prototype.GetStyle=function(){
97 var TempHTML="";
98
99 if(this.GetBrowserVersion()=="IE6"){
100 TempHTML="<div id=\""+this.ID+"\" style=\"_position:absolute; @Location\;width:auto;height:auto;margin:2px;padding:0px;width:"+this.Width+"px;height:"+this.Height+"px;\">";
101
102 switch(this.Location.toLowerCase()){
103 case "lefttop"://左上
104 TempHTML=TempHTML.replace("@Location","left:0px;_top:expression(eval(document.documentElement.scrollTop));");
105 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"',"+this.IE6CalibrationlsTop+");",1000);
106 break;
107 case "righttop"://右上
108 TempHTML=TempHTML.replace("@Location","right:0px;_top:expression(eval(document.documentElement.scrollTop));");
109 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"',"+this.IE6CalibrationlsTop+");",1000);
110 break;
111 case "leftbottom"://左下
112 TempHTML=TempHTML.replace("@Location","left:0px;_top:expression(eval(document.documentElement.scrollTop+"+document.documentElement.clientHeight+"-"+(this.Height+this.IE6CalibrationlsTop)+"));");
113 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"',"+this.IE6CalibrationlsTop+");",1000);
114 break;
115 case "rightbottom"://右下
116 TempHTML=TempHTML.replace("@Location","right:0px;_top:expression(eval(document.documentElement.scrollTop+"+document.documentElement.clientHeight+"-"+(this.Height+this.IE6CalibrationlsTop)+"));");
117 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"',"+this.IE6CalibrationlsTop+");",1000);
118 break;
119 case "left"://左居中
120 TempHTML=TempHTML.replace("@Location","left:0px;_top:expression(eval(document.documentElement.scrollTop+"+GetFloatOffsetTop(this.Height)+"));");
121 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"');",1000);
122 break;
123 case "right"://右居中
124 TempHTML=TempHTML.replace("@Location","right:0px;_top:expression(eval(document.documentElement.scrollTop+"+GetFloatOffsetTop(this.Height)+"));");
125 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"');",1000);
126 break;
127 case "centent"://屏幕居中
128 TempHTML=TempHTML.replace("@Location","_top:expression(eval(document.documentElement.scrollTop+"+GetFloatOffsetTop(this.Height)+"));_left:expression(eval(document.documentElement.scrollLeft+"+GetFloatOffsetLeft(this.Width)+"));");
129 setInterval("_CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"');",1000);
130 break;
131 default:
132 TempHTML=TempHTML.replace("@Location","left:0px;top:0px");
133 break;
134 }
135 }else{
136 TempHTML="<div id=\""+this.ID+"\" style=\"position:fixed!important; @Location\;width:auto;height:auto;margin:2px;padding:0px;width:"+this.Width+"px;height:"+this.Height+"px;\">";
137
138 switch(this.Location.toLowerCase()){
139 case "lefttop"://左上
140 TempHTML=TempHTML.replace("@Location","left:0px;top:0px");
141 break;
142 case "righttop"://右上
143 TempHTML=TempHTML.replace("@Location","right:0px;top:0px");
144 break;
145 case "leftbottom"://左下
146 TempHTML=TempHTML.replace("@Location","left:0px;bottom:0px");
147 break;
148 case "rightbottom"://右下
149 TempHTML=TempHTML.replace("@Location","right:0px;bottom:0px");
150 break;
151 case "left"://左居中
152 TempHTML=TempHTML.replace("@Location","left:0px;top:"+GetFloatOffsetTop(this.Height)+"px;");
153 setInterval("CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"');",1000);
154 break;
155 case "right"://右居中
156 TempHTML=TempHTML.replace("@Location","right:0px;top:"+GetFloatOffsetTop(this.Height)+"px;");
157 setInterval("CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"');",1000);
158 break;
159 case "centent"://居中
160 TempHTML=TempHTML.replace("@Location","right:"+GetFloatOffsetLeft(this.Width)+"px;top:"+GetFloatOffsetTop(this.Width)+"px;");
161 setInterval("CalibrationlsFloatOffset('"+this.ID+"','"+this.Location+"');",1000);
162 break;
163 default:
164 TempHTML=TempHTML.replace("@Location","left:0px;top:0px");
165 break;
166 }
167
168 }
169 if(this.CloseButton){
170 TempHTML+="<div style=\"font-size:12px;text-align:right\"><a href=\"javascript:void(0)\" style=\"color:#000000;text-decoration:none\" onclick=\"lsFloatClose('"+this.ID+"',"+this.IntervalShow+")\">关闭</a></div>";
171 }
172 TempHTML+="@InnerHTML</div>";
173
174 return TempHTML;
175 }
176 //初始化
177 lsFloat.prototype.Initialization=function(){
178 var Html=this.GetStyle();
179 Html=Html.replace("@InnerHTML",this.InnerHTML);
180 return Html;
181 }
182 ///显示
183 lsFloat.prototype.Show=function(){
184 this.Height+=18;
185 var html=this.Initialization();
186 document.write(html);
187 }