简体   繁体   English

猫头鹰传送带打破了引导模式

[英]Owl carousel breaks Bootstraps modals

I want to call Bootstrap modal when page loading. 我想在页面加载时调用Bootstrap模式。 but modal doesn't show properly and just body gets "modal-open" and body don't scroll because of style overflow hidden. 但是模态无法正确显示,只是主体被“模态打开”,并且主体由于隐藏的样式溢出而无法滚动。 I understand that because of being Owl carousel code in my js files this error happened. 我了解,由于在我的js文件中使用Owl轮播代码,因此发生了此错误。 when removing Owl carousel js file bootstrap works correctly. 删除Owl carousel js文件时,引导程序可以正常工作。

Is there any solution to this problem? 有什么解决办法吗?

In this link, you can see the problem. 在此链接中,您可以看到问题。 https://codepen.io/ghaem/pen/mzOLey https://codepen.io/ghaem/pen/mzOLey

Despite the $('#myModal').modal('show'); 尽管$('#myModal').modal('show'); modal don't run on loading page. 模态不在加载页面上运行。

Missing jquery document ready function 缺少jQuery文档准备功能

<script>
    $( document ).ready(function() {
        $('#myModal').modal('show');
    });
</script>

Just need to use $(document).ready(function() like below:- 只需使用$(document).ready(function()如下:

Now its working fine. 现在它的工作正常。

  $(document).ready(function(){ $('#myModal').modal('show'); }); 
 <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet"> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.1/js/bootstrap.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.3.4/owl.carousel.min.js"></script> <button type="button" class="btn btn-primary" data-toggle="modal" data-target=".bs-example-modal-lg">Large modal</button> <div id="myModal" class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel"> <div class="modal-dialog modal-lg" role="document"> <div class="modal-content"> ... </div> </div> </div> 

https://codepen.io/anon/pen/jeVpvM https://codepen.io/anon/pen/jeVpvM

you need to put your js in document ready 您需要将js放入文档中

$(document).ready(function(){
    $('#myModal').modal('show');
  });

try to instead, 尝试改为

$(document).ready(function(){
 $('#myModal').modal('show');
)};

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

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