让弹出的div居中

      //控制弹出div的形状     

      $("#dialogOrder").window({
                title: '添加新货位',
                zIndex: 10000,
                width: 350,
                collapsible: false,
                minimizable: false,
                maximizable: false,
                closable: false,
                closed: true,
                height: 300,
                draggable: true,
                resizable: false,
                shadow: true,
                modal: true
            })
        //保持弹出居中
        window.onscroll = function () {
            centerwh("#dialogOrder");
        }
        //DIV居中
        function centerwh(obj) {
            var h1 = document.body.clientHeight;
            var h2 = document.documentElement.clientHeight;
            var isXhtml = (h2 >= h1 && h2 != 0) ? true : false;

            var body = isXhtml ? document.documentElement : document.body;

            var wh = { left: 0, top: 0 };
            var vwh = { w: 0, h: 0 };

            vwh.w = $.browser.msie ? parseInt(body.clientWidth) : parseInt(windows.innerWidth);
            vwh.h = $.browser.msie ? parseInt(body.clientHeight) : parseInt(windows.innerHeight);
            wh.left = (vwh.w / 2) - parseInt($(obj).css("width")) / 2;
            wh.top = body.scrollTop + (vwh.h / 2) - parseInt($(obj).css("height")) / 2;

            if (wh.left <= 0) {
                wh.left = 0;
            }

            if (wh.top <= 0) {
                wh.top = 0;
            }

            var scrollTop = document.documentElement.scrollTop;
            $(obj).window("resize", { left: wh.left, top: wh.top })
        }

 

用的时候这样用:centerwh("#dialogOrder");这个dialogOrder是弹出div的id

注意:“#”是jquery里获取id的写法

让弹出的div居中

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值