为什么我的模态框不会在窗口的正中心打开?
我遇到了一个错误,我的模式无法在中心窗口中打开。我目前用来测量中间的代码如下:
var id = j('#share-modal');
// show modal, resize
j(id).css('top', j(window).height()/2-j(id).height()/2);
j(id).css('left', j(window).width()/2-j(id).width()/2);
j('#share-modal').fadeIn(500);
CSS
#share-modal {
display: none;
font-family: Arial, sans-serif;
width: 537px;
height: 510px;
position: absolute;
background: #FFF;
z-index: 100;
box-shadow: 3px 3px 3px #333;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
这是我放置的唯一应该使代码居中的代码,但我无法判断是否有其他东西干扰。
在这里查看我的 JavaScript: http://pastebin.com/wZeY5azT
您可以在这里查看:www.paultibbs.com/varier
向下滚动并单击“与朋友分享”按钮。
如果有人能帮助我解决这个错误,我将不胜感激!
I'm running into a bug where my modal won't open in the center window. The code i'm currently using to measure the middle is the following:
var id = j('#share-modal');
// show modal, resize
j(id).css('top', j(window).height()/2-j(id).height()/2);
j(id).css('left', j(window).width()/2-j(id).width()/2);
j('#share-modal').fadeIn(500);
CSS
#share-modal {
display: none;
font-family: Arial, sans-serif;
width: 537px;
height: 510px;
position: absolute;
background: #FFF;
z-index: 100;
box-shadow: 3px 3px 3px #333;
-moz-border-radius: 15px;
-webkit-border-radius: 15px;
}
This is the only code I put that is supposed to be centering the code, but I can't tell if something else is interfering.
View my Javascript here:
http://pastebin.com/wZeY5azT
You can view it here: www.paultibbs.com/varier
Scroll down and click on the "Share with friend" button.
If anyone can help me solve this bug, i'd be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 jQuery 文档:
http://docs.jquery.com/CSS/scrollTop
http://docs.jquery.com/CSS/height
通过 如何确定 jQuery 中窗口的高度和滚动位置?< /a>
From jQuery Docs:
http://docs.jquery.com/CSS/scrollTop
http://docs.jquery.com/CSS/height
via How do I determine height and scrolling position of window in jQuery?
您需要考虑滚动位置。
您还必须监视滚动事件并重新生成位置,以防它们上下滚动。
You need to take into account the scroll position.
You'll also have to maintain watch on the scroll event and regenerate the position in case they scroll up and down.