简体   繁体   English

Bootstrap模式背景滚动问题

[英]Bootstrap Modal Background Scrolling Issue

When my Bootstrap Modal Window is open, I have been unable to stop background scrolling from the main page. 当我的Bootstrap Modal窗口打开时,我无法停止从主页滚动背景。 I followed the directions given in this StackOverflow question, but I have been unsuccessful so far: Prevent BODY from scrolling when a modal is opened 我遵循了这个StackOverflow问题中给出的指示,但是到目前为止,我没有成功: 在打开模式时防止BODY滚动

On the left side, near top of this page, after it loads, you will see a button that says "Large Modal". 加载后,在此页面顶部附近的左侧,您将看到一个显示“大模态”的按钮。 If you click it, it will open a modal window. 如果单击它,它将打开一个模式窗口。 After its open, if you scroll up and down, you will see the background moving. 打开后,如果上下滚动,您会看到背景移动。 http://gettinmobile.com/home.html http://gettinmobile.com/home.html

I have added the CSS as directed in the stackoverflow question I linked to above: 我已经按照上面链接到的stackoverflow问题中的说明添加了CSS:

body.modal-open {
    overflow: hidden;
}

I have added the javascript shown on the same stackoverflow question, though I am not sure this is done correctly: 我添加了在同一stackoverflow问题上显示的javascript,尽管我不确定这样做是否正确:

   <script type='text/javascript'>

   $("#myModal").on("show", function () {
     $("body").addClass("modal-open");
   }).on("hidden", function () {
     $("body").removeClass("modal-open")
   });
   </script>

Any help would be appreciated, maybe someone can see what I'm doing wrong... thanks! 任何帮助将不胜感激,也许有人可以看到我在做什么错...谢谢!

You need to wait for jQuery to finish loading before you start binding events. 在开始绑定事件之前,您需要等待jQuery完成加载。 You can do this most simply with an anonymous function: 您可以使用匿名函数最简单地执行此操作:

$(function(){
    // YOUR CURRENT JS CODE HERE
});

在页面底部的JS代码中,尝试将“ $”符号替换为“ jQuery”(不带引号),看看是否有帮助,这在WordPress中很常见,很可能是问题的根源

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM