(JavaScript) Carousel and animating CSS - doesn't work

Hey everyone!

I want to install this Carousel
http://www.aurainweb.pl/2018/02/przykladowe-realizacje-karuzel-css-js/#Owl_carousel_and_Animatecss

  1. position (this yellow background)

on my webpage.
Here my index.html:


<!doctype html>
<html lang="en">
  <head>
    
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link rel="stylesheet" type="text/css" href="styles.css">

      <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'">
      
      
      
    <script  src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

      
      
      <script>
      $(document).ready(function (){
  // Declare Carousel jquery object
  var owl = $('.owl-carousel');

  // Carousel initialization
  owl.owlCarousel({
      loop:false,
      margin:0,
      navSpeed:500,
      nav:true,
      autoplay: true,
      rewind: true,
      items:1
  });


  // add animate.css class(es) to the elements to be animated
  function setAnimation ( _elem, _InOut ) {
    // Store all animationend event name in a string.
    // cf animate.css documentation
    var animationEndEvent = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';

    _elem.each ( function () {
      var $elem = $(this);
      var $animationType = 'animated ' + $elem.data( 'animation-' + _InOut );

      $elem.addClass($animationType).one(animationEndEvent, function () {
        $elem.removeClass($animationType); // remove animate.css Class at the end of the animations
      });
    });
  }

// Fired before current slide change
  owl.on('change.owl.carousel', function(event) {
      var $currentItem = $('.owl-item', owl).eq(event.item.index);
      var $elemsToanim = $currentItem.find("[data-animation-out]");
      setAnimation ($elemsToanim, 'out');
  });

// Fired after current slide has been changed
  var round = 0;
  owl.on('changed.owl.carousel', function(event) {

      var $currentItem = $('.owl-item', owl).eq(event.item.index);
      var $elemsToanim = $currentItem.find("[data-animation-in]");
    
      setAnimation ($elemsToanim, 'in');
  })
  
  owl.on('translated.owl.carousel', function(event) {
    console.log (event.item.index, event.page.count);
    
      if (event.item.index == (event.page.count - 1))  {
        if (round < 1) {
          round++
          console.log (round);
        } else {
          owl.trigger('stop.owl.autoplay');
          var owlData = owl.data('owl.carousel');
          owlData.settings.autoplay = false; //don't know if both are necessary
          owlData.options.autoplay = false;
          owl.trigger('refresh.owl.carousel');
        }
      }
  });
      </script>


    <title></title>
      
</head>
<body>

             
<div class="owl-carousel owl-theme">
      <div class="item">
        <h4 data-animation-in="fadeInUp" data-animation-out="animate-out fadeOutDown">Slide 1</h4>
        <p data-animation-in="rollIn" data-animation-out="animate-out rollOut">Cras a elementum dolor. Praesent aliquam sapien ac eros semper ullamcorper. Sed imperdiet enim at sodales suscipit. Aenean eget faucibus ipsum.</p>
        <p><a href="#" class="btn" data-animation-in="fadeInLeft" data-animation-out="animate-out fadeOutRight">Button 1</a></p>
      </div>
      <div class="item">
        <h4 data-animation-in="flipInY" data-animation-out="animate-out fadeOutUp">Slide 2</h4>
        <p data-animation-in="flipInX" data-animation-out="animate-out fadeOutLeft">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id dolor pulvinar, mollis orci vitae, molestie elit. Maecenas scelerisque ipsum nibh, id imperdiet nulla lobortis nec.</p>
        <p><a href="#" class="btn" data-animation-in="bounceInLeft" data-animation-out="animate-out bounceOutRight">Button 2</a></p>
      </div>
      <div class="item">
        <h4 data-animation-in="slideInDown" data-animation-out="animate-out slideOutUp">Slide 3</h4>
        <p data-animation-in="slideInRight" data-animation-out="animate-out fadeOut">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc id dolor pulvinar, mollis orci vitae, molestie elit. Maecenas scelerisque ipsum nibh, id imperdiet nulla lobortis nec.</p>
        <p><a href="#" class="btn" data-animation-in="slideInUp" data-animation-out="animate-out slideOutDown">Button 3</a></p>
      </div>
  </div>



</body>
</html>

Here my styles.css:

/* CSS FOR DEMO ONLY */
body {
  font-family: Arial, sans-serif;
}
.animated  {
  -webkit-animation-duration : 3s  ;
  animation-duration : 3s  ;

  -webkit-animation-delay : 500ms  ;
  animation-delay : 500ms  ;
}

.animate-out {
  -webkit-animation-delay : 0ms  ;
  animation-delay : 0ms  ;
}

h4 {
  font-size: 28px;
}

p {
  width: 50%;
  text-align: center;
  margin: 0 auto 20px;
}

.owl-item {
  display: table;
}

.owl-carousel .item {
  height: 80vh;
  background-color: #fc0;
  display: table-cell;
  vertical-align: middle;
  text-align: center;
}

.btn {
  display: inline-block;
  line-height: 35px;
  height: 35px;
  text-align: center;
  padding: 0 20px;
  width: auto;
  background-color: #000;
  text-decoration: none;
  color: #fff;
}

Why I have got only yellow background andand 3 buttons with text without prev next slider?

I’m guessing the Console is telling you the answer to this one, but its because you’ve copied a codepen without copying the resources too: You havent loaded Owl. Click on the bottom-left of the codepen to View the Resources used in that pen, and load the external JS and CSS there.

Thanks m_hutley

How can I load the external JS and CSS?
How looks the code to load it?

The same way you loaded jquery, load OWL.
The same way you loaded styles.css, load the other CSS files.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.