var msgBox = new function(){ var self = this; self.ok=1, self.warn=2, self.info=3, self.loading=4, self.hide=function(){ clearTimeout(self.time); $('.fusion_msgbox_wrap').remove(); }; var self = self; self.addCss = false; function typeStr(type){ if(type == self.ok) return 'ok'; else if(type==self.loading) return 'loading'; else if(type==self.warn) return 'warn'; else return 'info'; } function attachCss(){ var style = document.createElement('style'); style.type = 'text/css'; var css= '.fusion_msgbox_wrap{position:fixed;_position:absolute;left:0;top:-100px;width:100%;height:0;text-align:center;z-index:99200}.fusion_msgbox_board{display:inline-block;position:relative}.fusion_msgbox_mask{position:absolute;height:50px}.fusion_msgbox,.fusion_msgbox_left,.fusion_msgbox_left_icon,.fusion_msgbox_right{position:absolute;top:0;display:inline-block;height:48px;line-height:48px;background-image:url("http://qzonestyle.gtimg.cn/open/fusion/img/sprite.png?max_age=31104000&v=3");background-repeat:no-repeat}.fusion_msgbox{position:relative;padding:0 20px 0 50px;box-shadow:0 0 2px #565656;border:1px solid #999;font-weight:bold;font-size:14px;font-family:"Microsoft Yahei",tohama;color:#606060;background-position:0 -212px;background-repeat:repeat-x;background-color:#fff}.fusion_msgbox_left{left:0;width:2px;background-position:0 -164px}.fusion_msgbox_right{right:0;width:2px;background-position:-28px -164px}.fusion_msgbox_left_icon{left:10px;width:30px}.fusion_msgbox_left_ok .fusion_msgbox_left_icon{background-position:0 -20px}.fusion_msgbox_left_warn .fusion_msgbox_left_icon{background-position:0 -68px}.fusion_msgbox_left_info .fusion_msgbox_left_icon{background-position:0 -116px}.fusion_msgbox_left_loading{padding-left:38px}.fusion_msgbox_left_loading .fusion_msgbox_left_icon{top:16px;left:12px;height:16px;width:16px;background:transparent url("http://qzonestyle.gtimg.cn/open/fusion/img/loading.gif?max_age=31104000&v=1")}'; if(typeof style.styleSheet == 'undefined') style.innerHTML = css; else style.styleSheet.cssText = css; document.getElementsByTagName('head')[0].appendChild(style); self.addCss=true; } function create(msg, type){ if(!self.addCss) attachCss(); var tpl = '
'+ ''+ ''+ ''+ '{msg}'+ ''+ ''+ ''+ '
'; var height = Math.ceil( ($(window).height()) /2 ); tpl = tpl.replace(/\{type\}/, type); tpl = tpl.replace(/\{msg\}/, msg); tpl = tpl.replace(/\{height\}/g, height); $('body').append(tpl); } self.show=function(msg,type,timeout){ self.hide(); create(msg, typeStr(type)); if(timeout===0)return; if(!timeout)timeout = 3000; self.time = setTimeout(function(){ self.hide(); }, timeout); }; };