I have a problem, with a modal. I have a button on a page, that toggles the modal. When the modal shows up, the page jumps to top.

I have done everything I could to find a solution/etc, but I am really lost.

EDIT:

I have also tried with: $('#myModal').modal('show'); but it has the exact same effect.

推荐答案

When the modal opens a modal-open class is set to the <body> tag. This class sets overflow: hidden; to the body. Add this rule to your stylesheet to override the bootstrap.css style:

body.modal-open {
    overflow: visible;
}

Now the scroll should stay in place.

Jquery相关问答推荐

如何用each替换元素的attr href

确定元素是否是其父元素的最后一个子元素

在 div 中找到第一次出现的类

如何在数据表中显示空数据消息

在 jQuery UI Datepicker 中禁用future 日期

了解 Backbone.js REST 调用

如何使用给定的 url 判断图像是否存在?

jQuery scrollTop 在 Chrome 中不工作但在 Firefox 中工作

如何在 JQuery DataTable 中默认显示所有行

循环判断复选框并计算每个选中或未选中的复选框

输入元素上的 Javascript 更改事件仅在失go 焦点时触发

jQuery表格行中的每个循环

当 iframe 在 jQuery 中完成加载时,如何触发事件?

使用 jQuery 获取选中复选框的值

调整浏览器大小时如何自动居中 jQuery UI 对话框?

jQuery select2 获取 Select 标签的值?

将十六进制转换为 RGBA

如何在 ReactJS 中使用 JQuery

在 JavaScript 开头使用分号的目的是什么?

catch forEach 最后一次迭代