为什么我的模态框不会在窗口的正中心打开?

发布于 2025-01-04 00:55:45 字数 920 浏览 2 评论 0原文

我遇到了一个错误,我的模式无法在中心窗口中打开。我目前用来测量中间的代码如下:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甩你一脸翔 2025-01-11 00:55:45

来自 jQuery 文档:

var height = $(window).height();
var scrollTop = $(window).scrollTop();

http://docs.jquery.com/CSS/scrollTop
http://docs.jquery.com/CSS/height

通过 如何确定 jQuery 中窗口的高度和滚动位置?< /a>

From jQuery Docs:

var height = $(window).height();
var scrollTop = $(window).scrollTop();

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?

老娘不死你永远是小三 2025-01-11 00:55:45

您需要考虑滚动位置。

// Add the pageYOffset should fix the problem
j(id).css('top',  (j(window).height()/2-j(id).height()/2) + window.pageYOffset);

您还必须监视滚动事件并重新生成位置,以防它们上下滚动。

You need to take into account the scroll position.

// Add the pageYOffset should fix the problem
j(id).css('top',  (j(window).height()/2-j(id).height()/2) + window.pageYOffset);

You'll also have to maintain watch on the scroll event and regenerate the position in case they scroll up and down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文