jquery - 如何在绝对位置的滚动窗口中居中模态对话框?

标签 jquery css modal-dialog draggable center

我正在尝试将模态对话框置于滚动窗口的中心。这个模态是绝对位置的,因为必须可以在屏幕上拖动。我将此插件用于可拖动功能:

http://threedubmedia.com/code/event/drag

我的问题是,如果我将 top: 50% 放在中心窗口中,则此模式具有绝对位置,但不考虑所有滚动窗口。

最佳答案

你应该使用

position:fixed

而不是绝对/相对。

position:fixed The element is positioned relative to the browser window.

使用这个,你应该不会因为滚动而遇到任何问题。

http://www.w3schools.com/cssref/pr_class_position.asp

你也可以看到这个主题:

Fixed Positioning without Scrolling

How to place a div center of the window after scrolling

关于jquery - 如何在绝对位置的滚动窗口中居中模态对话框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12586840/

相关文章:

objective-c - 在 Cocoa 中设置 NSAlert 级别

modal-dialog - ngx-smart-modal - Angular 6

javascript - Bootstrap 多列轮播平滑滚动/缓动

html - 使用 bootstrap 3 将 div 中的文本对齐到底部

javascript - appendChild 在 IE 中无法正常工作

html - 使用 Bootstrap 的 Jumbotron 背景图片对我不起作用

html - 如何阻止 div 压低其他 div?

jquery - 我如何在jquery中同时从三个输入文本框中获取值

jquery - 如何删除 Jquery Mobile Panel 表单的填充?

javascript - 存储和输出表单数据