Bootstrap v3-打开模式窗口会强制页面向上滚动到顶部 [英] Bootstrap v3 - Opening a modal window forces the page to scroll up to the top

查看:53
本文介绍了Bootstrap v3-打开模式窗口会强制页面向上滚动到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我打开模式窗口时,它将背景上下文一直滚动到顶部.示例我在页面底部具有打开模式窗口的链接.当我单击链接时,窗口将向上滚动到文档顶部,然后显示模式窗口.我对模态窗口的定位没有任何问题.我只是不希望在打开页面之前发生向上滚动.我主要使用的是来自BS v3(​​最新发布在github上)的默认CSS和几乎所有的默认模式主体.我正在使用JS填充模式的标签和主体,然后将其打开

When I open a modal window it scrolls the background context all the way up to the top. Example I have links on the bottom of the page that open a modal window. When I click on the link the window will scroll up to the top of the document then display the modal window. I have no problem with the positioning of the modal window. I just don't want the scroll up to occur before it opens the page. I'm using mostly the default CSS that came from BS v3 (latest on github) and pretty much the default modal body. I am using JS to populate the label and body of the modal then opening it

<!-- Modal -->
<div class="modal fade" id="modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
        <h4 class="modal-title" id="myModalLabel">Modal title</h4>
      </div>
      <div class="modal-body" id="myModalBody"></div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

推荐答案

我发现问题是某些我经常强制使用滚动条的CSS.此CSS使身体的高度为100%.我删除此代码后,该模式就可以完美工作,而无需滚动到顶部.

I found the problem was some CSS I used to always force a scrollbar. This CSS gave the body a height of 100%. As soon as I removed this the modal worked perfectly without scrolling to top.

这篇关于Bootstrap v3-打开模式窗口会强制页面向上滚动到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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