specious / cloud9carousel

:cyclone: 3D-perspective carousel for jQuery / Zepto
http://j.mp/cloud9demo
233 stars 88 forks source link

Progress bar #41

Open Jack94son opened 2 years ago

Jack94son commented 2 years ago

Hi, thanks for implementing this awesome plugin! Would like to ask what if I want to add in the progress bar for the carousel?

Which callback function should I place the startProgressBar() and resetProgressBar()?

I tried to play around, but no luck for me.

onRendered: function( slider ) {
      var $totalSlide = slider.items.length;
      var item = slider.nearestIndex() + 1;

      $('.cmr-slider-counter > .current-counter').html(item);
      $('.cmr-slider-counter > .total-counter').html($totalSlide);

      startProgressBar(slider.autoPlayDelay);
  },
  onAnimateFinished: function( slider ) {
      resetProgressBar();
  }

this only worked once the carousel loaded. when the item changed, the progress bar not working.

specious commented 2 years ago

It seems like you could start the progress bar at the same time you set the carousel in motion, and update it on the onRendered event.

You know how many fps the carousel is set to update, and the logic inside playFrame() implicitly determines how many frames will be rendered before the carousel stops.

If you don't feel like "doing the math" from the formula, you could probably just tweak your progress update heuristic until the result looks about right.