metafizzy / flickity

:leaves: Touch, responsive, flickable carousels
https://flickity.metafizzy.co
7.53k stars 602 forks source link

autoPlay Instant option #712

Closed homerjam closed 6 years ago

homerjam commented 6 years ago

Hi @desandro

I may be able to work on a PR for this - would it be something you'd consider?

Basically I'd like the auto play behaviour to be instant as it is possible with next/previous using the API.

Thanks! James

desandro commented 6 years ago

You can hack this feature by adding this code:

Flickity.Player.prototype.tick = function() {
  // do not tick if not playing
  if ( this.state != 'playing' ) {
    return;
  }

  var time = this.parent.options.autoPlay;
  // default to 3 seconds
  time = typeof time == 'number' ? time : 3000;
  var _this = this;
  this.clear();
  this.timeout = setTimeout( function() {
    _this.parent.next( true, true );
    _this.tick();
  }, time );
};

See demo https://codepen.io/desandro/pen/6acdefb2b4fec682efc14f8ed90a5adc/


Add a 👍 reaction to this issue if you would like to see this feature properly added to Flickity. Do not add +1 comments — They will be deleted.

homerjam commented 6 years ago

Oh great thanks, I'll give that a go!

desandro commented 6 years ago

Looks like this feature request hasn't received much attention. Closing