Элементы карусели Owl не будут прокручиваться

Я пытаюсь заставить карусель совы работать в верхней части моей веб-страницы. Это было бы похоже на прокручиваемый раздел главных новостей. Когда вы нажимаете на навигацию, появляется новый элемент.

Это выглядит примерно так: введите здесь описание изображения

Это мой код:

$(document).ready(function(){
  $(".owl-carousel").owlCarousel();
});

jQuery(function($) {
      "use strict";

      $(".breaking").owlCarousel({

      loop:true,
      animateIn: 'fadeIn',
      autoplay:true,
      autoplayTimeout:3000,
      autoplayHoverPause:true,
      nav:true,
      margin:30,
      dots:false,
      mouseDrag:false,
      slideSpeed:500,
      navText: ["<i class="fas fa-angle-left"></i>", "<i class="fas fa-angle-right"></i>"],
      items : 1,
      responsive:{
            0:{
                  items:1
            },
            600:{
                  items:1
            }
      }

      });

}
:root {
    --main-accent: #f2552c;
}

.top-bar {
    background-color: #f2f2f2;
    border-bottom: 1px solid #e2e0e0;
    padding-top: 7px;
}

.top-bar .breaking-title {
    width: 200px;
}

.top-bar .breaking-title h6 {
    background: var(--main-accent);
    text-transform: uppercase;
    color: #ffffff;
    padding: 5px 10px;
    font-size: 13px;
    width: 123px;
    margin-right: 15px;
}

.post-content {
    /*z-index: 1;*/
    /*position: relative;*/
}

.top-bar .post-content {
    padding: 0;
}

.breaking .post-title.title-small {
    font-weight: 400;
    margin: 0;
    font-size: 14px;
    line-height: 20px;
}

.breaking .post-title a {
    color: #333333;
}

.breaking .post-title a:hover {
    text-decoration: none;
}


/* Carousel navigation */
.owl-carousel.owl-theme.breaking .owl-nav {
    position: absolute;
    right: 0;
    top: -3px;
    margin: 0;
}

.owl-carousel.owl-theme.breaking .owl-nav > div {
    background: var(--main-accent);
    border: 0;
    color: #fff;
}

.owl-carousel.owl-theme .owl-nav > div {
    margin: 0 3px;
    width: 20px;
    height: 20px;
    line-height: 20px;
    padding: 0;
    border-radius: 0;
    text-align: center;
    font-size: 12px;
    -webkit-transition: 400ms;
    -moz-transition: 400ms;
    -o-transition: 400ms;
    transition: 400ms;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0/css/all.min.css" rel="stylesheet"/>
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">

        <div class="top-bar">

            <div class="container">
                <div class="row">
                    <div class="col-md-8 d-flex breaking-news-bar">
                        <div class="breaking-title"><h6>Breaking news</h6></div>
                        
                        <div id="breaking" class="owl-carousel owl-theme owl-loaded breaking">

                            <div class="owl-stage-outer">

                                <div class="owl-stage" style="transform: translate3d(-3420px, 0px, 0px); transition: all 0s ease 0s; width: 7980px;">

                                    <div class="owl-item cloned" style="width: 1110px; margin-right: 30px;">
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">Soaring through Southern Patagonia with the</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>
                                    
                                    <div class="owl-item cloned" style="width: 1110px; margin-right: 30px;">
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">Super Tario Run isn’t groundbreaking, but it</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>
                                    
                                    <div class="owl-item" style="width: 1110px; margin-right: 30px;">
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">The best MacBook Pro alternatives in 2017</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>
                                    
                                    <div class="owl-item animated owl-animated-in fadeIn active" style="width: 1110px; margin-right: 30px;">	
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">Soaring through Southern Patagonia with the</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>
                                    
                                    <div class="owl-item" style="width: 1110px; margin-right: 30px;">
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">Super Tario Run isn’t groundbreaking, but it has</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>
                                    
                                    <div class="owl-item cloned" style="width: 1110px; margin-right: 30px;">
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">The best MacBook Pro alternatives in 2017</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>
                                    
                                    <div class="owl-item cloned" style="width: 1110px; margin-right: 30px;">
                                        <div class="item">
                            
                                           <div class="post-content">
                                              <h2 class="post-title title-small">
                                                 <a href="#">Soaring through Southern Patagonia with the</a>
                                              </h2>
                                           </div><!-- Post content end -->
                            
                                        </div>
                                    </div>


                                </div>

                            </div>

                            <div class="owl-nav">
                                <div class="owl-prev"><i class="fas fa-angle-left"></i></div>
                                <div class="owl-next"><i class="fas fa-angle-right"></i></div>
                            </div>
                            <div class="owl-dots disabled"></div>

                        </div> <!-- End breaking-news  -->
                    </div>

                    <div class="col-md-4">

                    </div>
                </div>
            </div>

        </div> <!-- End top-bar  -->

        <div class="header-content">

                <div class="container">

                </div>

        </div> <!-- End header-content  -->

        <div class="main-navigation">

            <div class="container">
                    
            </div>

        </div> <!-- End main-navigation  -->








    </div> <!-- End wrapper  -->

Когда я нажимаю на значки навигации, слайд не меняется. Любая помощь приветствуется, спасибо.


person PapT    schedule 07.03.2020    source источник
comment
Где находится файл js owl.carousel? Я думаю, что вам не хватает прикрепить файл плагина owl.carousel js.   -  person Raeesh Alam    schedule 07.03.2020
comment
Извините, все файлы добавлены в мой документ, я просто не смог добавить его в сниппет. В моем документе owl carousel файлы css и js включены правильно.   -  person PapT    schedule 07.03.2020
comment
Также убедитесь, что файл owl.carousel .js находится в нижней части библиотеки jQUery.   -  person Raeesh Alam    schedule 07.03.2020
comment
Да, это ниже jquery.   -  person PapT    schedule 07.03.2020
comment
Хорошо, позвольте мне загрузить рабочий фрагмент...   -  person Raeesh Alam    schedule 07.03.2020
comment
В приведенном выше коде js есть несколько проблем. например, два раза используйте кавычки "" в одной и той же строке передачи (["<i class="fas fa-angle-left"></i>", "<i class="fas fa-angle-right"></i>"],) в этой строке также ошибка ... должна быть одинарная кавычка.   -  person Raeesh Alam    schedule 07.03.2020
comment
Спасибо. Я исправил проблему с двойной кавычкой, но она все равно не двигается.   -  person PapT    schedule 07.03.2020
comment
так что вам нужна простая карусель для отображения текста с next и previous, как насчет без owl.carousel.js   -  person sanoj lawrence    schedule 07.03.2020
comment
Ну, все, что меня волнует, это дизайн. так что, пока это выглядит так, я не против использовать другую карусель.   -  person PapT    schedule 07.03.2020


Ответы (1)


Вам нужно изменить код style code, HTML structure и следовать структуре Owl-Carousel, поэтому не копируйте html-структуру owl-carousel из inspect-element, а также некоторые ошибки в вашем коде js. Теперь вы можете увидеть работающий код в моем фрагменте.
Надеюсь, это вам поможет...

jQuery(function($) {
  $(".breaking").owlCarousel({
    loop:true,
    autoplay:true,
    autoplayHoverPause: true,
    nav:true,
    margin: 30,
    dots:false,
    mouseDrag: false,
    navText: ['<i class="fas fa-angle-left"></i>', '<i class="fas fa-angle-right"></i>'],
    items : 1,
    responsive:{
      0:{
        items:1
      },
      600:{
        items:1
      }
    }
  });
});
:root {
  --main-accent: #f2552c;
}
.top-bar {
  background-color: #f2f2f2;
  border-bottom: 1px solid #e2e0e0;
  padding: 7px 0;
}
.top-bar .breaking-title {
  width: 140px;
  display: inline-block;
  background: var(--main-accent);
  text-transform: uppercase;
  color: #ffffff;
  padding: 5px 10px;
  font-size: 13px;
  text-align: center;
  white-space: nowrap;
  margin-right: 15px;
  font-weight: bold;
}
.breaking .post-title.title-small {
  font-weight: 400;
  margin: 0;
  font-size: 14px;
  line-height: 20px;
}
.breaking .post-title a {
  color: #333333;
}
.breaking .post-title a:hover {
  text-decoration: none;
}
/* Carousel navigation */
.breaking .owl-nav {
  position: absolute;
  right: 0;
  top: 0px;
  margin: 0;
}
.breaking .owl-nav .owl-prev,
.breaking .owl-nav .owl-next{
  background: var(--main-accent)!important;
  color: #ffffff!important;
  width: 20px;
  height: 20px;
  margin-left: 6px;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.12.0/css/all.min.css" rel="stylesheet"/>
<link href="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/assets/owl.carousel.min.css" rel="stylesheet" />
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" rel="stylesheet"/>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://owlcarousel2.github.io/OwlCarousel2/assets/owlcarousel/owl.carousel.js"></script>

<div class="wrapper">
  <div class="top-bar">
    <div class="container">
      <div class="row align-items-center">
        <div class="col-sm-4 text-right">
          <div class="breaking-title">Breaking news</div>
        </div>
        <div class="col-sm-8">
          <div id="breaking" class="owl-carousel breaking">
            <div class="item">
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">Soaring through Southern Patagonia with the</a>
                </h2>
              </div><!-- Post content end -->
            </div>
            <div class="item">
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">Super Tario Run isn’t groundbreaking, but it</a>
                </h2>
              </div><!-- Post content end -->
            </div>
            <div class="item">                  
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">The best MacBook Pro alternatives in 2017</a>
                </h2>
              </div><!-- Post content end -->
            </div>
            <div class="item">                  
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">Soaring through Southern Patagonia with the</a>
                </h2>
              </div><!-- Post content end -->
            </div>  
            <div class="item">                  
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">Super Tario Run isn’t groundbreaking, but it has</a>
                </h2>
              </div><!-- Post content end -->
            </div>
            <div class="item">                  
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">The best MacBook Pro alternatives in 2017</a>
                </h2>
              </div><!-- Post content end -->
            </div>
            <div class="item">
              <div class="post-content">
                <h2 class="post-title title-small">
                  <a href="#">Soaring through Southern Patagonia with the</a>
                </h2>
              </div><!-- Post content end -->
            </div>
          </div>
        </div>
      </div>
    </div>
  </div> <!-- End top-bar  -->
</div> <!-- End wrapper  -->

person Raeesh Alam    schedule 07.03.2020