由于需要,在网上搜了好多资料,最后觉得这个效果比较适合自己的需要,然后整理成自己喜欢的代码风格,放在这里。
if (this.timer > 0) {
window.clearInterval(me.timer);
}
var fun = function() {
if (me.pause == false || me.close) {
var x = me.left;
var y = 0;
var width = me.width;
var height = 0;
if (me.offset > 0) {
height = me.offset;
}
y = me.bottom - height;
if (y >= me.bottom) {
window.clearInterval(me.timer);
me.Pop.hide();
}
else {
me.offset = me.offset - me.step;
}
me.Pop.show(x, y, width, height);
}
}
this.timer = window.setInterval(fun, this.speed)
}
}
/**
** 消息卸载事件,可以重写
**/
msnMessage.prototype.onunload = function() {
return true;
}
/**
** 消息命令事件,要实现自己的连接,请重写它
**
**/
msnMessage.prototype.oncommand = function() {
//this.close = true;
window.open(this.action, this.target);
this.hide();
}
/**
** 消息显示方法
**/
msnMessage.prototype.show = function() {
var oPopup = window.createPopup(); //IE5.5+
this.Pop = oPopup;
var w = this.width;
var h = this.height;
var str = "<div style='border-right:#455690 1px solid;border-top: #a6b4cf 1px solid;z-index:99999;left:0px;bolder-left:#a6b4cf 1px solid;width:" + w + "px;border-bottom:#455690 1px solid;position:absolute;top:0px;height:" + h + "px;background-color:#c9d3f3'>";
str += "<table style="BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid" mce_style="BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid" cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>";
str += "<tr>";
str += "<td style="font-size:12px;color:#0f2c8c" mce_style="font-size:12px;color:#0f2c8c" width=30 height=24></TD>";
str += "<td style="padding-left:4px;font-weight: normal;font-size:12px;color:#1f336b;padding-top: 4px" mce_style="padding-left:4px;font-weight: normal;font-size:12px;color:#1f336b;padding-top: 4px" vAlign=center width='100%'>" + this.caption + "</td>";
str += "<td style="padding-right: 2px; padding-top: 2px" mce_style="padding-right: 2px; padding-top: 2px" vAlign=center align=right width=19>";
str += "<span title=关闭 style="font-weight: bold;font-size: 12px;cursor:hand;color: red;margin-right: 4px" mce_style="font-weight: bold;font-size: 12px;cursor:hand;color: red;margin-right: 4px" id='btSysClose' >×</span></td>";
str += "</tr>";
str += "<tr>";
str += "<td style="padding-right:1px;padding-bottom: 1px" mce_style="padding-right:1px;padding-bottom: 1px" colSpan=3 height=" + (h - 28) + ">";
str += "<div style='border-right:#b9c9ef 1px solid;padding-right:8px;border-top:#728eb8 1px solid;padding-left:8px;font-size:12px;padding-bottom:8px;border-left:#728eb8 1px solid;width:100%;color:#1f336b;padding-top: 8px;border-bottom:#b9c9ef 1px solid;height:100%'>" + this.title + "<br/><br/>";
str += "<div style="word-break:break-all" mce_style="word-break:break-all" align=left><a href="javascript:void(0)" mce_href="javascript:void(0)" hidefocus=true id='btCommand'><font color=#ff0000>" + this.message + "</font></a></div>";
str += "</div>";
str += "</td>";
str += "</tr>"
str += "</table>";
str += "</div>";
oPopup.document.body.innerHTML = str;
this.offset = 0;
var me = this;
oPopup.document.body.onmouseover = function() { me.pause = true; }
oPopup.document.body.onmouseout = function() { me.pause = false; }
var fun = function() {
var x = me.left;
var y = 0;
var width = me.width;
var height = me.height;
if (me.offset > me.height) {
height = me.height;
}
else {
height = me.offset;
}
y = me.bottom - me.offset;
if (y <= me.top) {
me.timeout--;
if (me.timeout == 0) {
window.clearInterval(me.timer);
if (me.autoHide) {
me.hide();
}
}
}
else {
me.offset = me.offset + me.step;
}
me.Pop.show(x, y, width, height);
}
this.timer = window.setInterval(fun, this.speed)
var btClose = oPopup.document.getElementById("btSysClose");
btClose.onclick = function() {
me.close = true;
me.hide();
}
var btCommand = oPopup.document.getElementById("btCommand");
btCommand.onclick = function() {
me.oncommand();
}
}
/**
** 设置速度方法
**/
msnMessage.prototype.speed = function(s) {
var t = 20;
try {
t = praseInt(s);
}
catch (e)
{ }
this.speed = t;
}
/**//*
** 设置步长方法
**/
msnMessage.prototype.step = function(s) {
var t = 1;
try {
t = praseInt(s);
}
catch (e)
{ }
this.step = t;
}
msnMessage.prototype.rect = function(left, right, top, bottom) {
try {
this.left = left != null ? left : this.right - this.width;
this.right = right != null ? right : this.left + this.width;
this.bottom = bottom != null ? (bottom > screen.height ? screen.height : bottom) : screen.height;
this.top = top != null ? top : this.bottom - this.height;
}
catch (e)
{ }
}
// --></script>
调用代码 :
效果图: