Search code examples
jqueryhtmlcssowl-carousel

How to add Owl-Carousel-2 completeness percent(%) status bar(not progressBar)?


First of all this is not about "progressBar", I need a completeness percent(%) status bar for owlCarousel-2, if there is any confusion in my question and description then please check the images below.

I have just created a pen, please check the link - https://codepen.io/tsarkar/pen/NmpGmV

a busy cat

a busy cat
(source: testyourprojects.biz)

I just have complete with "Total Item count" and "Current item count", but can't implement the status(%) bar like the images I have posted. Please check my code below.

$(function(){
var owl = $('.ivySlide');
$('.ivySlide').owlCarousel({
  smartSpeed: 500,
  items: 1,
  margin:0,
  nav:true,
  dots:false,
  onInitialized:counter,
  onTranslated:counter
});
function counter(event) {
  var element = event.target;
  var items = event.item.count;
  var item = event.item.index + 1;
  var sldtxt = $('.active .ivySlideTxt').html();
  $('#counter').html(item+" / "+items)
}
});

Solution

  • Finally I have got the solutions for this, please check the code below and also the pen.

    $(function(){
    $('.ivySlide').owlCarousel({
      smartSpeed: 500,
      items: 1,
      margin:0,
      nav:true,
      dots:false,
      onInitialized:counter,
      onTranslated:counter
    });
    function counter(event) {
      var element = event.target;
      var items = event.item.count;
      var item = event.item.index + 1;
      var sldtxt = $('.active .ivySlideTxt').html();
      var sldWidth = 100;
      var sldPercent = sldWidth * item / items;
      $('#counter').html(item+" / "+items)
      $('.slTxt').html(sldtxt);
      $('.slideState span').css("width", sldPercent + "%");
      $('.slideState span').html(sldPercent + "%")
    }
    });
    

    You can check my solution here https://codepen.io/tsarkar/pen/NmpGmV