消息提示封装js
/** ---------------------------------------------------------------------------- var pop = new popWindow({id:"netSpeed",width:250,height:150,caption:"网速提示",title:"加载当前页面用时",message:time+"ms"}); pop.show(); ---------------------------------------------------------------------------- /**//* * 消息构造 */ var popWindow = function(arg){ this.id = (typeof arg.id == "undefined") ?"popTemp":arg.id; this.title = (typeof arg.title == "undefined") ?"内容如下":arg.title; this.caption= (typeof arg.caption == "undefined") ?"消息提示":arg.caption; this.message= (typeof arg.message == "undefined") ?" ":arg.message; this.target = (typeof arg.target == "undefined") ?" ":arg.target; this.action = (typeof arg.action == "undefined") ?" ":arg.action; this.width = (typeof arg.width == "undefined") ?250:arg.width; this.height = (typeof arg.height == "undefined") ?150:arg.height; this.speed = 20; this.step = 1; this.right = screen.width -1; this.bottom = screen.height; this.left = this.right - this.width; this.top = this.bottom - this.height; this.timer = 0; this.stayTimer= 0; this.pause = false; this.close = false; this.stay = (typeof arg.stay == "undefined") ?3:arg.stay;//默认设置为三秒 this.autoHide = (typeof arg.autoHide == "undefined") ?true:arg.autoHide; } /**//* * 隐藏消息方法 */ popWindow.prototype.hide = function(){ if(this.onunload()){ var offset = this.height>this.bottom-this.top?this.height:this.bottom-this.top; var me = this; if(this.timer>0){ window.clearInterval(me.timer); } if(this.stayTimer>0){ window.clearTimeout(me.stayTimer); } 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); } } /** * 消息卸载事件 */ popWindow.prototype.onunload = function() { return true; } /** * 消息命令事件 */ popWindow.prototype.oncommand = function(){ //this.close = true; this.hide(); window.open("http://wangsuceshi.hao352.com/"); } /** * 消息显示方法 */ popWindow.prototype.show = function(){ var oPopup = window.createPopup(); //IE5.5+ this.Pop = oPopup; var w = this.width; var h = this.height; var str = "<div style=\"width:250px;height:145px;margin:0 auto;background:url(images/box_bg.gif) no-repeat;padding:4px 0 0 4px;position:relative;\">" + " <div style=\"background:url(images/box_top.png) no-repeat;height:23px;;\">" + " <h2 style=\"padding-left:16px;width:100px;float:left\"></h2>" + " <div title=关闭 style=\"background-image:url(images/box_close1.png); width:23px; height:22px; cursor:pointer; float:right; z-index:1; margin-right:7px;\" id=\"btSysClose\"onmouseover=\"this.style.backgroundImage='url(images/box_close2.png)';\" onmouseout=\"this.style.backgroundImage='url(images/box_close1.png)';\"></div>" + " </div>" + " <div style=\"width:240px;\">" + " <div class=\"notic\">" + " <div class=\"text\" style=\"padding:6px 5px 6px 5px;text-indent:2em;line-height:138%;height:90px;color:#000000;cursor:pointer;overflow-y:auto;font-size:12px;\">" + this.title + ":" + "<a href=\"#none\" id='btCommand' style=\"text-decoration: none; color:#000;\" onmouseover=\"this.style.color='#f60'\" onmouseout=\"this.style.color='#000'\">" + this.message + "</a>" + " </div>" + " </div>" + " </div>" + "</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){ window.clearInterval(me.timer); if(me.autoHide){ me.stayTimer = window.setTimeout(function(){me.hide()},me.stay*1000); } } 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(); } } /** ** 设置速度方法 **/ popWindow.prototype.speed = function(s){ var t = 20; try { t = praseInt(s); } catch(e){} this.speed = t; } /** ** 设置步长方法 **/ popWindow.prototype.step = function(s){ var t = 1; try { t = praseInt(s); } catch(e){} this.step = t; } popWindow.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){} } function showMsg(time){ var pop = new popWindow({id:"netSpeed"+time,width:250,height:150,caption:"网速提示",title:"加载当前页面用时",message:time+"ms",autoHide:true,stay:4}); pop.rect(null,null,null,screen.height-50); pop.speed = 10; pop.step = 5; pop.show(); } /** var pop = new popWindow({id:"netSpeed",width:250,height:150,caption:"网速提示",title:"加载当前页面用时",message:"1ms"}); pop.rect(null,null,null,screen.height-50); pop.speed = 10; pop.step = 5; pop.show(); */ /** var pop2 = new popWindow({id:"netSpeed",width:250,height:150,caption:"网速提示",title:"加载当前页面用时",message:"2ms"}); pop2.rect(100,null,null,screen.height); pop2.show(); */