div屏幕居中

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>DIV屏幕居中</title>

</head>

 

<body>

<script language="javascript">

var tips = function(options){

  //对象唯一标识

  this.id = 'tips_' + new Date().getTime();

 

  //对象宽高

  this.padding = options.padding || 0;

  this.msg = options.msg || '';

 

  //对象

  this.obj = document.createElement('div');

 

  //设置属性

  this.obj.id = this.id;

  this.obj.style.position = 'absolute';

  this.obj.style.margin = '0';

  this.obj.style.backgroundColor = '#FFF';

  this.obj.style.padding = this.padding + 'px';

  this.obj.innerHTML = this.msg;

 

  //加入到body

  document.body.appendChild(this.obj);

 

  //实际高度

  this.width = document.getElementById(this.id).offsetWidth;

  this.height = document.getElementById(this.id).offsetHeight;

 

  //设置top left

  var body = (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;

  var left = body.scrollLeft + (body.clientWidth - this.width)/2;

  var top = body.scrollTop + (body.clientHeight - this.height)/2;

 

  //更改位置

  this.obj.style.left = left + 'px';

  this.obj.style.top = top + 'px';

 

  this.html = function(html){

    document.getElementById(this.id).innerHTML = html;

  };

 

  //关闭

  this.close = function(){

    document.getElementById(this.id).style.display = 'none';

  };

};

//调用:

new tips({msg:'<div style="border:#CCC solid 5px;padding:10px 20px; font-size:12px; text-align:center;"><div>正在更新报表,请稍后……</div><div>这一般需要 10 秒钟</div></div>'});

</script>

</body>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值