北漂IT民工 的博客

javascript 提示的对话框


var iMsgBox = function(msg, dom){

var mask = document.createElement(‘div’);

var pop = document.createElement(‘div’);

var message = document.createElement(‘h4’);

dom = dom || document.body;

message.innerHTML = msg;

var timed = false;

var closed = false;

var close = function(){

closed = true;

if(!timed) return;

dom.removeChild(mask);

dom.removeChild(pop);

}

var timeClose = function(){

timed = true;

if(closed) close();

};

setTimeout(timeClose, 1500);

pop.appendChild(message);

dom.appendChild(mask);

dom.appendChild(pop);

mask.style.cssText = ‘position:absolute;background:#000;opacity:0.3;width:100%;*filter: Alpha(Opacity=30);top:0;left:0;z-index:10000’;

mask.style.display = ‘block’;

mask.style.height = dom.clientHeight + dom.scrollTop+ ‘px’;

dom.style.overflow = ‘hidden’;

pop.style.cssText = ‘position:absolute;width:200;padding:8px 20px;background:#fff;border:0px solid #ccc;text-align:center;z-index:10001;’;

pop.style.display = ‘block’;

pop.style.left = dom.offsetWidth / 2 - pop.offsetWidth / 2 + ‘px’;

pop.style.top = dom.offsetHeight / 2 - pop.offsetHeight / 2 + ‘px’;

return {

close: close

};

}