/*
* Author: sohighthesky
* From: http://blog.csdn.net/sohighthesky
* Date: 2009-11-9
*/
/*
* Box indicates the message box or its id to be displayed.
* Options: see the notes in setOptions in the code.
*/
Var sheyMsg = function (box, options ){
This. box = this. g (box );
This. setOptions (options );
This. init ();
}
SheyMsg. prototype = {
AE: function (e, call ){
If (window. addEventListener) window. addEventListener (e, call, false );
Else window. attachEvent ("on" + e, call );
},
G: function (id) {return typeof (id) = "string "? Document. getElementById (id): id ;},
IsFixed :! Window. ActiveXObject | (navigator. userAgent. indexOf ("MSIE 6") =-1 & document. compatMode = "CSS1Compat "),
SetOptions: function (options ){
This. options = {// Default Configuration
ShowDelay: 10, // display latency
AutoHide: 30, // Auto Hide time. If it is set to 0, Auto Hide is not enabled.
OnShow: function () {}, // call after display
OnHide: function () {}// hide and call
};
For (var o in options ){
This. options [o] = options [o];
}
},
Hide: function () {// hide
Var _ top = this. box. clientHeight;
Var o = this;
If (/ing $/. test (o. status) return;
O. status = "hiding ";
ClearTimeout (o. tt );
O. t = setInterval (function (){
If (o. isFixed)
O. box. style. bottom = (-o. box. clientHeight + (-- _ top) + 'px ';
Else
O. box. style. top = o.de. scrollTop + o.de. clientHeight-5-(-- _ top) + "px ";
If (_ top =-5 ){
ClearInterval (o. t );
O. status = "hide ";
O. box. style. display = "none ";
O. options. onHide ();
}
}, 5 );
},
Show: function () {// display
Var _ top = 0;
Var o = this;
If (/ing $/. test (o. status) return;
O. status = "showing ";
ClearTimeout (o. tt );
O. box. style. display = "block ";
O. t = setInterval (function (){
If (o. isFixed)
O. box. style. bottom = (-o. box. clientHeight + (++ _ top) + "px ";
Else
O. box. style. top = (o.de. scrollTop + o.de. clientHeight-5-(++ _ top) + "px ";
If (_ top = o. box. clientHeight ){
ClearInterval (o. t );
O. status = "show ";
O. options. onShow ();
Var h = o. options. autoHide-0;
If (h) o. tt = setTimeout (function () {o. hide () ;}, h * 1000 );
}
}, 1 );
},
FixIE6: function () {// rolling position of IE6
This. box. style. left = this.de. scrollLeft + this.de. clientWidth-this.box.clientWidth-2 + "px ";
If (this. status = "show "){
This. box. style. top = this.de. scrollTop + this.de. clientHeight-this.box.clientHeight-5 + "px ";
} Else if (this. status = "hide "){
This. box. style. top = this.de. scrollTop + this.de. clientHeight + 5 + "px ";
}
},
Init: function (){
With (this. box. style ){
Display = "block"; // the width and height can be taken out after the display.
If (this. isFixed ){
Position = "fixed ";
Right = "2px ";
Bottom = (-this. box. clientHeight-5) + "px ";
} Else {
Position = "absolute ";
}
}
This. status = "hide ";
Var o = this;
If (! This. isFixed ){
O.de = document. compatMode = "CSS1Compat "? Document.doc umentElement: document. body;
Var timer;
This. AE ("resize", function () {clearTimeout (timer); timer = setTimeout (function () {o. fixIE6.call (o)}, 30 );});
This. AE ("scroll", function () {clearTimeout (timer); timer = setTimeout (function () {o. fixIE6.call (o)}, 30 );});
This. fixIE6 (); // specifies the position when loading
}
O. box. style. display = "none ";
O. tt = setTimeout (function () {o. show () ;}, o. options. showDelay * 1000 );
}
}
This article from the CSDN blog, reproduced please indicate the source: http://blog.csdn.net/sohighthesky/archive/2009/11/10/4795886.aspx