//控制弹出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居中](https://i-blog.csdnimg.cn/blog_migrate/a4c26d1e5885305701be709a3d33442f.gif)