2015-09-29 95 views
1

我使用OWL Carousel,試圖lazyLoad後添加.border-red<div class="item">,意味着調用這個函數lazyLoad afterLazyLoad

後:$(".item").addClass("border-red");懶加載時。意思是在OWLCarousel lazyLoaded之後添加類函數執行。添加類OWL的旋轉木馬afterLazyLoad

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
OWLCarousel demo>
如何addclassØ功能後執行WLCarousel lazyLoaded?

+1

您需要設置'afterLazyLoad'爲'真',你的選擇,就像你'lazyLoad'和'做導航'。您應該能夠通過此選項更新訪問回調函數。 –

+0

@TylerSloan嗨,謝謝,但如何訪問回調函數? – Aariba

+0

@ vijayP的回答很好。 –

回答

3

試試這個:

$(document).ready(function() { 

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

}); 

這裏afterLazyLoad是一個回調函數

+0

嗨,謝謝,但沒有工作:( – Aariba

+0

剛剛看到了貓頭鷹傳送帶的執行情況,上面的代碼做了小改動,請您再試一次這個更新的代碼嗎? – vijayP

+0

Hi it works,Progress Bar has gone,mean進度條沒有顯示,下面是進度條的演示:http://owlgraphic.com/owlcarousel/demos/progressBar.html – Aariba