Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.0/assets/owl.carousel.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/OwlCarousel2/2.2.0/assets/owl.theme.default.min.css">

<div class="container mt-2">
  <div class="row">
    <div class="col-xs-12 col-md-5">
      <h1 class="text-xs-center text-md-left">Owl 2 Carousel Callback</h1>
      <p class="text-xs-center text-md-left">
        Swipe through the cards and watch the callback do its magic.
      </p>
      <h5>Here is a solution on how to get the correct index, without looking for the active class!</h5>
    </div>
    <div class="col-xs-12 col-md-7">

      <!-- Set up your HTML -->
      <div class="phone">
        <div class="owl-wrapper">
          <div class="row">
            <div class="col-xs-12">
              <div class="titlebar">
                Paymentinformation
              </div>
            </div>
          </div>
          <div class="loop owl-carousel owl-theme">
            <div>
              <div>Card1</div>
              <div class="card-number">
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>1234</span>
              </div>
            </div>
            <div>
              <div>Card2</div>
              <div class="card-number">
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>1234</span>
              </div>
            </div>
            <div>
              <div>Card3</div>
              <div class="card-number">
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>1234</span>
              </div>
            </div>
            <div>
              <div>Card4</div>
              <div class="card-number">
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>●●●● - </span>
                <span>1234</span>
              </div>
            </div>
          </div>
          <div class="container">
            <div class="row">
              <div class="col-xs-12">
                <div class="card">
                  <div class="card-block jsCallback">
                    <div class="card-content loading">
                      <p><strong><span class="dummy-title"></span></strong></p>
                      <p>
                        <span class="dummy-parapgraph"></span>
                        <span class="dummy-parapgraph"></span>
                        <span class="dummy-parapgraph"></span>
                      </p>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            <div class="row">
              <div class="col-xs-12">
                <div class="btn btn-primary btn-block jsBtn">
                  Button
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato:100,300,400,400i,700,900');
$color1: #4ac;
$color2: #4ac3be;
$amount: 10;
body,
html {
  font-family: 'Lato';
}

.phone {
  margin: 2em auto;
  width: 400px;
  max-width: 100%;
  background: #000;
  padding: 4em 1em;
  border-radius: 2em;
  box-shadow: 0 50px 50px -30px rgba(0,0,0,0.7), 0 50px 50px -50px rgba(0,0,0,0.7);
}

.titlebar {
  text-align: center;
  padding: 0.5em;
  background: $color2;
  font-size: 1.2em;
  color: white;
}

.card-block {
  transition: all 0.2s ease-out;
}

.card-content {
  text-align: justify;
  &.loading {
    animation: loading .4s linear infinite alternate;
    ;
  }
}

.dummy-title {
  display: inline-block;
  background: #ddd;
  width: 80%;
  height: 10px;
  border-radius: 5px;
}

.dummy-parapgraph {
  display: inline-block;
  background: #eee;
  width: 100%;
  height: 8px;
  border-radius: 5px;
  &:last-child {
    width: 60%;
  }
}

.owl-wrapper {
  background-color: rgba(240, 240, 240, 1);
  height: 600px;
}

.owl-carousel {
  & .card-number {
    opacity: 0.6;
    margin-top: 3em;
    text-align: right;
  }
  & .owl-item {
    background: white;
    padding: 1.5em;
    border-radius: 4px;
    opacity: 0.3;
    box-shadow: 0 4px 4px -1px rgba(0, 0, 0, 0.4);
    margin: 1em 0;
    transform: scale(0.9);
    transition: all 0.4s ease-out;
    &.center {
      opacity: 1;
      transform: scale(1);
      &:hover {
        box-shadow: 0 8px 16px -5px rgba(0, 0, 0, 0.4);
      }
    }
  }
}

.btn {
  background: $color1;
  border-color: transparent;
  transition: background 0.2s ease-out;
  &:hover,
  &:active,
  &:focus {
    background: darken($color1, $amount)!important;
    border-color: transparent!important;
  }
  &:active {
    background: darken($color1, $amount*2)!important;
  }
  &[disabled] {
    opacity: 0.3;
    -webkit-filter: grayscale(1);
    filter: grayscale(1);
  }
}

@keyframes loading {
  from {
    opacity: 0.3;
  }
  to {
    opacity: 1;
  }
}
              
            
!

JS

              
                $(document).ready(function() {
  var contentHtml = '<div class="card-content"><p><strong>{{ title }}</strong></p><p>{{ content }}</p></div>';
  var errorHTML = "<div class='alert-danger'>No Data available, Card4 has no data to see what happens when there is an error</div>";
  var callbackContainer = document.querySelectorAll(".jsCallback")[0];
  var loadingHTML = callbackContainer.innerHTML;
  var btn = document.querySelector(".jsBtn");

  /* Templating micro */
  var tmpl = function(t) {
    var code = 'with(o){return \'' + t.replace(/{{\s*(.+?)\s*}}/g, '\'+($1)+\'') + '\';}';
    return new Function('o', code);
  };
  var render = tmpl(contentHtml);

  /* callback FN */
  var afterFn = function(event) {
    var maxCount = event.item.count;
    var currentItem = (event.item.index - 2) % maxCount;
    if (currentItem <= 0 || currentItem > maxCount) {
      currentItem = 0;
    }
    callbackContainer.innerHTML = loadingHTML;
    btn.setAttribute('disabled', "disabled");

    /* Timeout to simulate loadingtimes */
    setTimeout(function() {
      console.log(typeof data[currentItem]);
      if (typeof data[currentItem] == 'object') {
        var finalHTML = render(data[currentItem]);
        callbackContainer.innerHTML = finalHTML;
        btn.removeAttribute('disabled');
      } else {
        callbackContainer.innerHTML = errorHTML;
      }
    }, 1000);
  }

  /* initialize owl */
  var $owl = $('.loop');
  $owl.owlCarousel({
    autoplay: true,
    autoplayHoverPause: true,
    autoplayTimeout: 3000,
    autoplaySpeed: 800,
    center: true,
    items: 1.3,
    stagePadding: 16,
    loop: true,
    margin: 16,
    onChanged: afterFn
  });

});

/* json data */
var data = [{
  title: "Cardtitle 1",
  content: "Card 4 ist not in this json, this should fire an error. Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
}, {
  title: "Cardtitle  2",
  content: "Card 4 ist not in this json, this should fire an error. Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
}, {
  title: "Cardtitle  3",
  content: "Card 4 ist not in this json, this should fire an error. Lorem ipsum dolor sit amet, consetetur sadipscing elitr."
}];
              
            
!
999px

Console