我正在使用OWL Carousel,尝试在lazyLoad之后将类.border-red添加到<div class="item">,意味着在lazyLoad afterLazyLoad之后调用此函数

示例:延迟加载时$(".item").addClass("border-red");。表示添加类函数在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>


这是OWLCarousel Options and Callbacks

猫头鹰轮播demo>

OWLCarousel lazyLoaded后如何执行addclass函数?

最佳答案

尝试这个:

$(document).ready(function() {

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

});


这里afterLazyLoad是一个回调函数

07-25 23:29