首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何对这个JQuery对话框进行中心设置?

如何对这个JQuery对话框进行中心设置?
EN

Stack Overflow用户
提问于 2014-07-22 16:54:13
回答 2查看 305关注 0票数 0

我一直在使用这样的JQuery对话框:$(thisDialog).dialog();,直到我了解到它不喜欢IE9模式,而doctype严格不是一个选项,因为遗留代码,我如何从这个例子的弹出式中心?

http://jsfiddle.net/46jYC/3/

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-22 16:57:15

考虑模态对话框的jQuery解决方案是位置绝对/相对/固定的:

代码语言:javascript
复制
var windowHeight = $(window).height();
var windowWidth = $(window).width();
var boxHeight = $('.modal-dialog').height();
var boxWidth = $('.modal-dialog').width();
$('.modal-dialog').css({'left' : ((windowWidth - boxWidth)/2), 'top' : ((windowHeight - boxHeight)/2)}); //change selector to whatever your selector is :)

考虑到模态对话框不是位置绝对/相对/固定的jQuery解决方案:

css:

代码语言:javascript
复制
margin-left: auto;
margin-right: auto;

jquery:

代码语言:javascript
复制
var windowHeight = $(window).height();
var boxHeight = $('.modal-dialog').height();
$('.modal-dialog').css({'margin-top' : ((windowHeight - boxHeight )/2)});  //change selector to whatever your selector is :)
票数 1
EN

Stack Overflow用户

发布于 2014-07-22 16:57:08

你应该写这样的东西:

代码语言:javascript
复制
function abrirPopup(url,w,h) {
    var newW = w + 100;
    var newH = h + 100;
    var left = (screen.width - newW) / 2;
    var top = (screen.height - newH) / 2;
    var newwindow = window.open(url, 'name', 'width=' + newW +
            ',height=' + newH + ',left=' + left + ',top=' + top);
    newwindow.resizeTo(newW, newH);

    //posiciona o popup no centro da tela
    //(position the popup in the center of the canvas)
    newwindow.moveTo(left, top);
    newwindow.focus();
    return false;
}

HTML:

代码语言:javascript
复制
<a href="#" onclick="return abrirPopup('http://www.google.com.br', 500, 400)">Google</a>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24893290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档