title: Lazy Load Owl Carousel with Picturefill
body: <p>I am using the Owl Carousel and Picturefill plugins and I would like to lazy load the main slider images. Any help would be appreciated. In the example url, click on the "Responsive" thumbnail (second image after the YouTube thumbnail). Then expand/contract your browser window and you should see the image referenced being updated depending on the size of the browser.</p>
  
  <p><strong>Example url:</strong></p>
  
  <p><a href="http://dx1showroom.azurewebsites.net/picturefill/2.html" rel="nofollow">http://dx1showroom.azurewebsites.net/picturefill/2.html</a></p>
  
  <p><strong>Goals:</strong></p>
  
  <ul>
  <li>Use Owl Carousel - www.owlcarousel.owlgraphic.com</li>
  <li>With Picturefill - <a href="http://scottjehl.github.io/picturefill/" rel="nofollow">http://scottjehl.github.io/picturefill/</a></li>
  <li>Sync with second owl carousel slider</li>
  <li>And lazy load main slider</li>
  </ul>
  
  <p><strong>I have working:</strong></p>
  
  <ul>
  <li>Owl carousels are working</li>
  <li>Synced carousels (main &amp; thumbnail sliders)</li>
  <li>Loading images with Picturefill</li>
  </ul>
  
  <p><strong>HTML:</strong></p>
  
  <pre><code>&lt;div class="thumbnail-frame"&gt;
      &lt;div id="sliderStatus" class="image-count"&gt;
          &lt;span class="glyphicon icon-camera"&gt;&lt;/span&gt;
          &lt;span class="currentItem"&gt;&lt;span class="result"&gt;&lt;/span&gt;&lt;/span&gt;/&lt;span class="owlItems"&gt;&lt;span class="result"&gt;&lt;/span&gt;&lt;/span&gt;
      &lt;/div&gt;
  
      &lt;div id="slideshow-main" class="owl-carousel main-frame col-sm-8 col-md-8 col-lg-9"&gt;
          &lt;div class="item video"&gt;&lt;iframe width="563" height="422" src="//www.youtube.com/embed/GZL6piSl5P8?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
          &lt;div class="item"&gt;
              &lt;picture&gt;
                  &lt;!--[if IE 9]&gt;&lt;video style="display: none;"&gt;&lt;![endif]--&gt;
                  &lt;source srcset="http://placehold.it/1300x867" media="(min-width: 1200px)"&gt;
                  &lt;source srcset="http://placehold.it/1000x667" media="(min-width: 992px)"&gt;
                  &lt;source srcset="http://placehold.it/800x533" media="(min-width: 768px)"&gt;
                  &lt;source srcset="http://placehold.it/650x433" media="(min-width: 600px)"&gt;
                  &lt;source srcset="http://placehold.it/460x307" media="(min-width: 400px)"&gt;
                  &lt;source srcset="http://placehold.it/320x213" media="(min-width: 100px)"&gt;
                  &lt;!--[if IE 9]&gt;&lt;/video&gt;&lt;![endif]--&gt;
                  &lt;img srcset="http://placehold.it/1300x867" alt="Picturefill Test"&gt;
              &lt;/picture&gt;
          &lt;/div&gt;
          &lt;div class="item video"&gt;&lt;iframe width="563" height="422" src="//www.youtube.com/embed/akhmS1D2Ce4?rel=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;
          &lt;div class="item"&gt;
              &lt;picture class="lazyOwl"&gt;
                  &lt;!--[if IE 9]&gt;&lt;video style="display: none;"&gt;&lt;![endif]--&gt;
                  &lt;source srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg" media="(min-width: 1200px)"&gt;
                  &lt;source srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg?width=1000" media="(min-width: 992px)"&gt;
                  &lt;source srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg?width=800" media="(min-width: 768px)"&gt;
                  &lt;source srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg?width=650" media="(min-width: 600px)"&gt;
                  &lt;source srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg?width=460" media="(min-width: 400px)"&gt;
                  &lt;source srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg?width=320" media="(min-width: 100px)"&gt;
                  &lt;!--[if IE 9]&gt;&lt;/video&gt;&lt;![endif]--&gt;
                  &lt;img srcset="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg" alt="Picturefill Test"&gt;
                  &lt;/picture&gt;
              &lt;/div&gt;    
          &lt;/div&gt;
  
          &lt;div id="slideshow-thumbnails" class="owl-carousel thumbnail-frame"&gt;
              &lt;div class="item"&gt;&lt;a&gt;&lt;img src="http://img.youtube.com/vi/GZL6piSl5P8/1.jpg" alt="" class="img-responsive"&gt;&lt;/a&gt;&lt;/div&gt;
              &lt;div class="item"&gt;&lt;a&gt;&lt;img src="http://placehold.it/135x90&amp;amp;text=Responsive" alt="" class="img-responsive"&gt;&lt;/a&gt;&lt;/div&gt;
              &lt;div class="item"&gt;&lt;a&gt;&lt;img src="http://img.youtube.com/vi/akhmS1D2Ce4/1.jpg" alt="" class="img-responsive"&gt;&lt;/a&gt;&lt;/div&gt;
              &lt;div class="item"&gt;&lt;a&gt;&lt;img src="https://media.dx1app.com/v1/media/53d68f53b43a22e37500027f.jpg?width=300" alt="" class="img-responsive"&gt;&lt;/a&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  </code></pre>
  
  <p><strong>JavaScript:</strong></p>
  
  <pre><code>$(document).ready(function() {
  
      // Owl Slider Function
      function sync(el){
          var current = this.currentItem;
          $("#slideshow-thumbnails")
              .find(".owl-item")
              .removeClass("synced")
              .eq(current)
              .addClass("synced")
          if($("#slideshow-thumbnails").data("owlCarousel") !== undefined){
              center(current)
          }
  
          updateResult(".owlItems", this.owl.owlItems.length);
          updateResult(".currentItem", this.owl.currentItem +1);
      }
  
      // Owl Slider Function
      function center(number){
          var owlSync2visible = owlSync2.data("owlCarousel").owl.visibleItems;
          var num = number;
          var found = false;
  
          for(var i in owlSync2visible){
              if(num === owlSync2visible[i]){
                  var found = true;
              }
          }
  
          if(found===false){
              if(num&gt;owlSync2visible[owlSync2visible.length-1]) {
                  owlSync2.trigger("owl.goTo", num - owlSync2visible.length+2)
              } else {
                  if(num - 1 === -1){
                      num = 0;
                  }
                  owlSync2.trigger("owl.goTo", num);
                  }
          } else if(num === owlSync2visible[owlSync2visible.length-1]) {
              owlSync2.trigger("owl.goTo", owlSync2visible[1])
          } else if(num === owlSync2visible[0]){
              owlSync2.trigger("owl.goTo", num-1)
          }
      }
  
      function updateResult(pos,value){
          sliderStatus.find(pos).find(".result").text(value);
      }
  
  
      // Owl Slider
      var sliderStatus = $("#sliderStatus");
  
      var owlSync1 = $("#slideshow-main").owlCarousel({
          singleItem : true,
          slideSpeed : 500,
          navigation: true,
          pagination: false,
          // itemsScaleUp: true,
          afterAction : sync,
          responsiveRefreshRate : 200,
          navigation: true,
          navigationText: [
              '&lt;span class="thumb-prev"&gt;&lt;span class="glyphicon icon-prev-arrow"&gt;&lt;/span&gt;&lt;/span&gt;',
              '&lt;span class="thumb-next"&gt;&lt;span class="glyphicon icon-next-arrow"&gt;&lt;/span&gt;&lt;/span&gt;'
          ],
          afterUpdate : function() {
              sliderMainMaxHeight('#slideshow-main');
              posSliderControls('#slideshow-main');
              posAlignImgVertically('#slideshow-main');
          }
      });
  
      var owlSync2 = $("#slideshow-thumbnails").owlCarousel({
          items : 8,
          itemsDesktop      : [1199,8],
          itemsDesktopSmall     : [992,8],
          itemsTablet       : [768,6],
          itemsMobile       : [520,3],
          pagination:false,
          responsiveRefreshRate : 100,
          scrollPerPage: true,
          navigation: true,
          navigationText: [
              '&lt;span class="thumb-prev"&gt;&lt;span class="glyphicon icon-prev-arrow"&gt;&lt;/span&gt;&lt;/span&gt;',
              '&lt;span class="thumb-next"&gt;&lt;span class="glyphicon icon-next-arrow"&gt;&lt;/span&gt;&lt;/span&gt;'
          ],
          afterInit : function(el){
              el.find(".owl-item").eq(0).addClass("synced");
          },
          afterUpdate : function() {
              sliderMainMaxHeight('#slideshow-thumbnails');
              posSliderControls('#slideshow-thumbnails');
              posSliderImgCounter('#slideshow-thumbnails');
              posAlignImgVertically('#slideshow-thumbnails');
          }
      });
  
      $("#slideshow-thumbnails").on("click", ".owl-item", function(e){
          e.preventDefault();
          var number = $(this).data("owlItem");
          owlSync1.trigger("owl.goTo",number);
      });
  
      $(".owl-carousel").fitVids();;
  });
  </code></pre>