$(document).ready(function() { var $newSlideConf = $('.post_gallery'); var items = parseInt($newSlideConf.attr('data-items')); var speed = parseInt($newSlideConf.attr('data-speed')); var autoPlay = parseInt($newSlideConf.attr('data-autoplay')); var time = parseInt($newSlideConf.attr('data-time')); var loop = parseInt($newSlideConf.attr('data-loop')); var arrow = parseInt($newSlideConf.attr('data-arrow')); var pagination = parseInt($newSlideConf.attr('data-pagination')); var move = parseInt($newSlideConf.attr('data-move')); var pausehover = parseInt($newSlideConf.attr('data-pausehover')); var md = parseInt($newSlideConf.attr('data-md')); var sm = parseInt($newSlideConf.attr('data-sm')); var xs = parseInt($newSlideConf.attr('data-xs')); var xxs = parseInt($newSlideConf.attr('data-xxs')); if(autoPlay==1) { if(time){ autoPlay = time; }else{ autoPlay = '3000'; } }else{ autoPlay = false; } if(pausehover){pausehover = true}else{pausehover=false} if(move){move = false}else{move=true} if(arrow){arrow =true}else{arrow=false} if(pagination==1){pagination = true}else{pagination=false} if(loop==1){loop = true}else{loop=false} var newSlide = $(".post_gallery .newSlide"); newSlide.owlCarousel({ autoplay : autoPlay , smartSpeed: speed, loop: loop, autoplayHoverPause: pausehover, scrollPerPage: move, nav: arrow, dots : pagination, responsive:{ 0:{ items:xxs, }, 480:{ items:xs, }, 768:{ items:sm, nav:false, }, 992:{ items:md, }, 1200:{ items:items, } } }); checkClasses(); newSlide.on('translated.owl.carousel', function(event) { checkClasses(); }); function checkClasses(){ var total = $('.post_gallery .newSlide .owl-stage .owl-item.active').length; $('.post_gallery ').each(function(){ $(this).find('.owl-item').removeClass('firstActiveItem'); $(this).find('.owl-item').removeClass('lastActiveItem'); $(this).find('.owl-item.active').each(function(index){ if (index === 0) { $(this).addClass('firstActiveItem'); } if (index === total - 1 && total>1) { $(this).addClass('lastActiveItem'); } }) }); } });