右下角message

1     #msg_win{border:1px solid #f80;background:#9eceeb;width:300px;position:absolute;right:0;margin:0px;display:none;overflow:hidden;z-index:99;}
2     #msg_win .icos{position:absolute;top:2px;*top:0px;right:2px;z-index:9;}
3     .icos a{float:left;color:#833B02;margin:1px;text-align:center;text-decoration:none;font-family:webdings;}
4     .icos a:hover{color:#fff;}
5     #msg_title{background:#9eceeb;border-bottom:1px solid #f80;color:#000;height:25px;line-height:25px;text-indent:5px; font-size:14px; color:Red;}
6     #msg_content{margin:8px;width:300px;height:200px;overflow:hidden;}
View Code
1     <div id="msg_win" style="display: none; top: 490px; visibility: visible; opacity: 1;">
2         <div class="icos">
3             <a id="msg_min" title="最小化" href="javascript:void(0);">_</a><a id="msg_close" title="关闭"
4                 href="javascript:void(0);">×</a></div>
5         <div id="msg_title">
6             订单受理提醒:</div>
7         <div id="msg_content">
8         </div>
9     </div>
View Code
 1         var Message = {
 2             set: function () {//最小化与恢复状态切换
 3                 var set = this.minbtn.status == 1 ? [0, 1, 'block', this.char[0], '最小化'] : [1, 0, 'none', this.char[1], '恢复'];
 4                 this.minbtn.status = set[0];
 5                 this.win.style.borderBottomWidth = set[1];
 6                 this.content.style.display = set[2];
 7                 this.minbtn.innerHTML = set[3]
 8                 this.minbtn.title = set[4];
 9                 this.win.style.top = this.getY().top;
10             },
11             close: function () {//关闭
12                 this.win.style.display = 'none';
13                 window.onscroll = null;
14             },
15             setOpacity: function (x) {//设置透明度
16                 var v = x >= 100 ? '' : 'Alpha(opacity=' + x + ')';
17                 this.win.style.visibility = x <= 0 ? 'hidden' : 'visible'; //IE有绝对或相对定位内容不随父透明度变化的bug
18                 this.win.style.filter = v;
19                 this.win.style.opacity = x / 100;
20             },
21             show: function () {//渐显
22                 clearInterval(this.timer2);
23                 var me = this, fx = this.fx(0, 100, 0.1), t = 0;
24                 this.timer2 = setInterval(function () {
25                     t = fx();
26                     me.setOpacity(t[0]);
27                     if (t[1] == 0) { clearInterval(me.timer2) }
28                 }, 10);
29             },
30             fx: function (a, b, c) {//缓冲计算
31                 var cMath = Math[(a - b) > 0 ? "floor" : "ceil"], c = c || 0.1;
32                 return function () { return [a += cMath((b - a) * c), a - b] }
33             },
34             getY: function () {//计算移动坐标
35                 var d = document, b = document.body, e = document.documentElement;
36                 var s = Math.max(b.scrollTop, e.scrollTop);
37                 var h = /BackCompat/i.test(document.compatMode) ? b.clientHeight : e.clientHeight;
38                 var h2 = this.win.offsetHeight;
39                 return { foot: s + h + h2 + 2 + 'px', top: s + h - h2 - 2 + 'px' }
40             },
41             moveTo: function (y) {//移动动画
42                 clearInterval(this.timer);
43                 var me = this, a = parseInt(this.win.style.top) || 0;
44                 var fx = this.fx(a, parseInt(y));
45                 var t = 0;
46                 this.timer = setInterval(function () {
47                     t = fx();
48                     me.win.style.top = t[0] + 'px';
49                     if (t[1] == 0) {
50                         clearInterval(me.timer);
51                         me.bind();
52                     }
53                 }, 10);
54             },
55             bind: function () {//绑定窗口滚动条与大小变化事件
56                 var me = this, st, rt;
57                 window.onscroll = function () {
58                     clearTimeout(st);
59                     clearTimeout(me.timer2);
60                     me.setOpacity(0);
61                     st = setTimeout(function () {
62                         me.win.style.top = me.getY().top;
63                         me.show();
64                     }, 600);
65                 };
66                 window.onresize = function () {
67                     clearTimeout(rt);
68                     rt = setTimeout(function () { me.win.style.top = me.getY().top }, 100);
69                 }
70             },
71             init: function () {//创建HTML
72                 function $(id) { return document.getElementById(id) };
73                 this.win = $('msg_win');
74                 var set = { minbtn: 'msg_min', closebtn: 'msg_close', title: 'msg_title', content: 'msg_content' };
75                 for (var Id in set) { this[Id] = $(set[Id]) };
76                 var me = this;
77                 this.minbtn.onclick = function () { me.set(); this.blur() };
78                 this.closebtn.onclick = function () { me.close() };
79                 this.char = navigator.userAgent.toLowerCase().indexOf('firefox') + 1 ? ['_', '::', '×'] : ['0', '2', 'r']; //FF不支持webdings字体
80                 this.minbtn.innerHTML = this.char[0];
81                 this.closebtn.innerHTML = this.char[2];
82                 setTimeout(function () {//初始化最先位置
83                     me.win.style.display = 'block';
84                     me.win.style.top = me.getY().foot;
85                     me.moveTo(me.getY().top);
86                 }, 0);
87                 return this;
88             }
89         };
View Code

 

posted on 2014-03-04 11:12  slnt  阅读(211)  评论(0编辑  收藏  举报

导航