微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Owl Carousel 在我的代码中不起作用出了什么问题?

如何解决Owl Carousel 在我的代码中不起作用出了什么问题?

当我尝试运行它时,我的猫头鹰旋转木马没有出现。我链接到正确的样式表和正确的脚本 - 但我什么也没看到。

我尝试在本地和直接从 carousel github 链接到样式表 - 但我仍然一无所获。

是否有可能头部中的某些代码阻止了执行?

<!DOCTYPE html>
<html lang="en" style="height: 300px;">
    <head>
        <Meta charset="utf-8">
        <Meta http-equiv="X-UA-Compatible" content="IE=edge">
        <Meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
        <Meta name="description" content="">
        <Meta name="author" content="">
        <title>Blank Template for Bootstrap</title>
        <!-- Bootstrap core CSS -->
        <link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
        <!-- Custom styles for this template -->
        <link rel="stylesheet" href="blocks.css">
        <link href="style.css" rel="stylesheet">
        <script>/* Pinegrow Interactions,do not remove */ (function(){try{if(!document.documentElement.hasAttribute('data-pg-ia-disabled')) { window.pgia_small_mq=typeof pgia_small_mq=='string'?pgia_small_mq:'(max-width:767px)';window.pgia_large_mq=typeof pgia_large_mq=='string'?pgia_large_mq:'(min-width:768px)';var style = document.createElement('style');var pgcss='html:not(.pg-ia-no-preview) [data-pg-ia-hide=""] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show=""] {opacity:1;visibility:visible;display:block;}';if(document.documentElement.hasAttribute('data-pg-id') && document.documentElement.hasAttribute('data-pg-mobile')) {pgia_small_mq='(min-width:0)';pgia_large_mq='(min-width:99999px)'} pgcss+='@media ' + pgia_small_mq + '{ html:not(.pg-ia-no-preview) [data-pg-ia-hide="mobile"] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show="mobile"] {opacity:1;visibility:visible;display:block;}}';pgcss+='@media ' + pgia_large_mq + '{html:not(.pg-ia-no-preview) [data-pg-ia-hide="desktop"] {opacity:0;visibility:hidden;}html:not(.pg-ia-no-preview) [data-pg-ia-show="desktop"] {opacity:1;visibility:visible;display:block;}}';style.innerHTML=pgcss;document.querySelector('head').appendChild(style);}}catch(e){console&&console.log(e);}})()</script>
        <link rel="stylesheet" href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css">
        <link rel="stylesheet" href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.theme.default.min.css"> 
    </head>
    <body>
        <div class="container">
</div>
        <!-- Bootstrap core JavaScript
    ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->
        <nav class="navbar navbar-expand-lg navbar-light bg-light"> 
            <div class="container-fluid"> 
                <a class="navbar-brand" href="#">Navbar</a> 
                <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarToggler11" aria-controls="" aria-expanded="false" aria-label="Toggle navigation"> 
                    <span class="navbar-toggler-icon"></span> 
                </button>                 
                <div class="collapse navbar-collapse" id="navbarToggler11"> 
                    <ul class="navbar-nav me-auto mb-2 mb-lg-0"> 
                        <li class="nav-item"> 
                            <a class="nav-link active" href="#">Home</a> 
                        </li>                         
                        <li class="nav-item"> 
                            <a class="nav-link" href="#">Link</a> 
                        </li>                         
                        <li class="nav-item"> 
                            <a class="nav-link disabled" href="#">disabled</a> 
                        </li>                         
                        <li class="nav-item dropdown"> 
                            <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink12" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">                                        Dropdown link                                    </a> 
                            <div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink12"> 
                                <a class="dropdown-item" href="#">Action</a> 
                                <a class="dropdown-item" href="#">Another action</a> 
                                <a class="dropdown-item" href="#">Something else here</a> 
                            </div>                             
                        </li>                         
                    </ul>                     
                    <form class="d-flex"> 
</form>                     
                </div>                 
            </div>             
        </nav>
        <div class="owl-carousel owl-theme"> 
            <div>
                <img src="https://www.w3schools.com/css/img_fjords.jpg" alt="">
            </div>             
            <div>
                <img src="https://www.w3schools.com/css/img_fjords.jpg" alt="">
            </div>             
            <div>
                <img src="https://www.w3schools.com/css/img_fjords.jpg" alt="">
            </div>             
            <div>
                <img src="https://www.w3schools.com/css/img_fjords.jpg" alt="">
            </div>             
        </div>
        <section style="height: 400px; background-attachment: fixed; background-position: center; background-size: cover; background-repeat: no-repeat; background-image: url('Downloads/jeriden-villegas-VLPUm5wP5Z0-unsplash%20(1).jpg');" data-pg-ia-scene='{"l":[{"a":"pxBckElement"}]}'>
            <section style="height: 400px; background-attachment: fixed; background-position: center; background-size: cover; background-repeat: no-repeat; opacity: 0.2; background-color: #3eaedf;" data-pg-ia-scene='{"l":[{"a":"pxBckElement"}]}'></section>
        </section>
        <script src="assets/js/popper.min.js"></script>
        <script src="bootstrap/js/bootstrap.min.js"></script>
        <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
        <script type="text/javascript" src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>
        <script src="pgia/lib/pgia.js"></script>
    </body>
</html>

解决方法

您在样式表和脚本方面做得很好。您只是缺少一个脚本来启动带有参数的轮播。我在这里附上脚本和屏幕截图,它现在工作正常: Owl Carousel Working Perfect

Owl Carousel MUST script to show output 您必须在代码中的所有脚本标记之后添加以下脚本: <script> $('.owl-carousel').owlCarousel({ loop:true,margin:10,responsiveClass:true,responsive:{ 0:{ items:1,nav:true },600:{ items:3,nav:false },1000:{ items:5,nav:true,loop:false } } }) </script>

如果您在这方面需要任何进一步的帮助,请告诉我。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。