Add class on OWL Carousel afterLazyLoad

2019-01-29 11:56发布

I'm using OWL Carousel, trying to add class .border-red to <div class="item"> after lazyLoad, means call this function after lazyLoad afterLazyLoad

Example: $(".item").addClass("border-red"); when lazy loaded. Means add class function execute after OWLCarousel lazyLoaded.

JS

$(document).ready(function() {

$("#owl-demo").owlCarousel({
items : 4,
lazyLoad : true,
navigation : true
});

});

HTML

<div id="owl-demo" class="owl-carousel">
    <div class="item"><img class="lazyOwl" data-src="assets/owl1.jpg" alt="Lazy Owl Image"></div>
    <div class="item"><img class="lazyOwl" data-src="assets/owl1.jpg" alt="Lazy Owl Image"></div>
    <div class="item"><img class="lazyOwl" data-src="assets/owl2.jpg" alt="Lazy Owl Image"></div>
    <div class="item"><img class="lazyOwl" data-src="assets/owl3.jpg" alt="Lazy Owl Image"></div>
    <div class="item"><img class="lazyOwl" data-src="assets/owl5.jpg" alt="Lazy Owl Image"></div>
</div>

Here is OWLCarousel Options and Callbacks
OWLCarousel demo >
How to addclass function execute after OWLCarousel lazyLoaded?

1条回答
ゆ 、 Hurt°
2楼-- · 2019-01-29 12:30

try this:

$(document).ready(function() {

   $("#owl-demo").owlCarousel({
      items : 4,
      lazyLoad : true,
      navigation : true,
      afterLazyLoad: function(elem){
          $(elem).addClass("border-red");
      }
   });

});

Here afterLazyLoad is a callback function

查看更多
登录 后发表回答