标签:
一、引入css样式
1 <!-- 浮动窗口样式css begin --> 2 <style type="text/css"> 3 #msg_win{border:1px solid #A67901;background:#EAEAEA;width:240px;position:absolute;right:0;font-size:12px;font-family:Arial;margin:0px;display:none;overflow:hidden;z-index:99;} 4 #msg_win .icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;} 5 .icos a{float:left;color:#833B02;margin:1px;text-align:center;font-weight:bold;width:14px;height:22px;line-height:22px;padding:1px;text-decoration:none;font-family:webdings;} 6 .icos a:hover{color:#fff;} 7 #msg_title{background:#BBDEF6;border-bottom:1px solid #A67901;border-top:1px solid #FFF;border-left:1px solid #FFF;color:#000;height:25px;line-height:25px;text-indent:5px;} 8 #msg_content{margin:5px;margin-right:0;width:230px;height:126px;overflow:hidden;} 9 </style> 10 <!-- 浮动窗口样式css end -->
二、html标签以及内容
1 <!-- 浮动窗口html代码 begin --> 2 <hr> 3 <div id="msg_win" style="display:block;top:490px;visibility:visible;opacity:1;"> 4 <div class="icos"> 5 <a id="msg_min" title="最小化" href="javascript:void 0">_</a><a id="msg_close" title="关闭" href="javascript:void 0">× 6 </a> 7 </div> 8 <div id="msg_title"> 9 设备运行情况--> 10 </div> 11 <div id="msg_content" style="overflow:auto;height:150px;width:100%;white-space:nowrap"> 12 <s:property value="devRun" escape="false"/>//要显示的内容 13 14 </div> 15 </div> 16 <!-- 浮动窗口html代码 end -->
三、引入js,必须放到最后
1 <script language="javascript"> 2 var Message={ 3 set: function() {//最小化与恢复状态切换 4 var set=this.minbtn.status == 1?[0,1,‘block‘,this.char[0],‘最小化‘]:[1,0,‘none‘,this.char[1],‘展开‘]; 5 this.minbtn.status=set[0]; 6 this.win.style.borderBottomWidth=set[1]; 7 this.content.style.display =set[2]; 8 this.minbtn.innerHTML =set[3] 9 this.minbtn.title = set[4]; 10 this.win.style.top = this.getY().top; 11 }, 12 close: function() {//关闭 13 this.win.style.display = ‘none‘; 14 window.onscroll = null; 15 }, 16 setOpacity: function(x) {//设置透明度 17 var v = x >= 100 ? ‘‘: ‘Alpha(opacity=‘ + x + ‘)‘; 18 this.win.style.visibility = x<=0?‘hidden‘:‘visible‘;//IE有绝对或相对定位内容不随父透明度变化的bug 19 this.win.style.filter = v; 20 this.win.style.opacity = x / 100; 21 }, 22 show: function() {//渐显 23 clearInterval(this.timer2); 24 var me = this,fx = this.fx(0, 100, 0.1),t = 0; 25 this.timer2 = setInterval(function() { 26 t = fx(); 27 me.setOpacity(t[0]); 28 if (t[1] == 0) {clearInterval(me.timer2) } 29 },10); 30 }, 31 fx: function(a, b, c) {//缓冲计算 32 var cMath = Math[(a - b) > 0 ? "floor": "ceil"],c = c || 0.1; 33 return function() {return [a += cMath((b - a) * c), a - b]} 34 }, 35 getY: function() {//计算移动坐标 36 var d = document,b = document.body, e = document.documentElement; 37 var s = Math.max(b.scrollTop, e.scrollTop); 38 var h = /BackCompat/i.test(document.compatMode)?b.clientHeight:e.clientHeight; 39 var h2 = this.win.offsetHeight; 40 return {foot: s + h + h2 + 2+‘px‘,top: s + h - h2 - 2+‘px‘} 41 }, 42 moveTo: function(y) {//移动动画 43 clearInterval(this.timer); 44 var me = this,a = parseInt(this.win.style.top)||0; 45 var fx = this.fx(a, parseInt(y)); 46 var t = 0 ; 47 this.timer = setInterval(function() { 48 t = fx(); 49 me.win.style.top = t[0]+‘px‘; 50 if (t[1] == 0) { 51 clearInterval(me.timer); 52 me.bind(); 53 } 54 },10); 55 }, 56 bind:function (){//绑定窗口滚动条与大小变化事件 57 var me=this,st,rt; 58 window.onscroll = function() { 59 clearTimeout(st); 60 clearTimeout(me.timer2); 61 me.setOpacity(0); 62 st = setTimeout(function() { 63 me.win.style.top = me.getY().top; 64 me.show(); 65 },600); 66 }; 67 window.onresize = function (){ 68 clearTimeout(rt); 69 rt = setTimeout(function() {me.win.style.top = me.getY().top},100); 70 } 71 }, 72 init: function() {//创建HTML 73 function $(id) {return document.getElementById(id)}; 74 this.win=$(‘msg_win‘); 75 var set={minbtn: ‘msg_min‘,closebtn: ‘msg_close‘,title: ‘msg_title‘,content: ‘msg_content‘}; 76 for (var Id in set) {this[Id] = $(set[Id])}; 77 var me = this; 78 this.minbtn.onclick = function() {me.set();this.blur()}; 79 this.closebtn.onclick = function() {me.close()}; 80 this.char=navigator.userAgent.toLowerCase().indexOf(‘firefox‘)+1?[‘_‘,‘::‘,‘ב]:[‘0‘,‘2‘,‘r‘];//FF不支持webdings字体 81 this.minbtn.innerHTML=this.char[0]; 82 this.closebtn.innerHTML=this.char[2]; 83 setTimeout(function() {//初始化最先位置 84 me.win.style.display = ‘block‘; 85 me.win.style.top = me.getY().foot; 86 me.moveTo(me.getY().top); 87 },0); 88 return this; 89 } 90 }; 91 Message.init(); 92 </script>
标签:
原文地址:http://www.cnblogs.com/pi-qingwen/p/5109894.html