Bootstrap 模式:切换时背景跳到顶部 [英] Bootstrap modal: background jumps to top on toggle

查看:29
本文介绍了Bootstrap 模式:切换时背景跳到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模态问题.我在页面上有一个按钮,可以切换模式.当模态出现时,页面跳转到顶部.

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.

我也试过:$('#myModal').modal('show'); 但效果完全一样.

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

推荐答案

当模态打开时,modal-open 类被设置为 标签.此类将 overflow: hidden; 设置为正文.将此规则添加到您的样式表以覆盖 bootstrap.css 样式:

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.

这篇关于Bootstrap 模式:切换时背景跳到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆