New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to programmatically pause and resume? #94
Comments
By 'pause' do you mean disable dragging, or pause [@desandro edit] See metafizzy/flickity-docs#5 (comment) for the Player API |
Pause autoPlay. So while the video is playing it does not try going to the next slide but when the video is done I can programatically restart autoPlay. |
Overall I think it would be good to provide methods for stop, play and pause. I think I saw in another issue that you had said you didn't think it would be a good user experience to continue animating after a user clicked on a slide. Not that I disagree with you, but I think that should be up to the person implementing Flickity and not a choice of the library itself. This is especially true because of the commercial licensing and people paying for the library. If someone pays to use this they should be able to chose how they use it. |
This seems as easy as this: // -------------------------- Flickity -------------------------- //
// utils.extend( Flickity.defaults, {
// autoPlay: false
// });
Flickity.createMethods.push('_createPlayer');
Flickity.prototype._createPlayer = function() {
this.player = new Player( this );
this.on( 'activate', this.activatePlayer );
this.on( 'uiChange', this.stop );
this.on( 'pointerDown', this.stop );
this.on( 'deactivate', this.deactivatePlayer );
};
Flickity.prototype.activatePlayer = function() {
if ( !this.options.autoPlay ) {
return;
}
this.player.play();
eventie.bind( this.element, 'mouseenter', this );
this.isMouseenterBound = true;
};
Flickity.prototype.stop = function() {
this.player.stop();
};
Flickity.prototype.play = function() {
this.player.play();
};
Flickity.prototype.pause = function() {
this.player.pause();
};
Flickity.prototype.unpause = function() {
this.player.unpause();
};
Flickity.prototype.deactivatePlayer = function() {
this.player.stop();
if ( this.isMouseenterBound ) {
eventie.unbind( this.element, 'mouseenter', this );
delete this.isMouseenterBound;
}
}; |
You can just use |
+1! |
I'm quite new to JS. Can someone please post a complete example of how to pause autoplay? |
<div class="main-gallery">...</div> $('.main-gallery').flickity({
// options
cellAlign: 'left',
contain: true
});
var flkty = Flickity.data( $('.main-gallery')[0] );
flkty.deactivatePlayer(); |
Thanks! |
@desandro edit: this code is not recommended
|
@drastick Not sure if I got it right |
v1.2.0 has added proper auto-play API: Closing this issue as resolved 🐳 |
the link is incorrect, it points to localhost, should be this https://flickity.metafizzy.co/api.html#player |
I have videos in my slides and would like to pause flickity while the video is playing and then resume it once the video is done.
The text was updated successfully, but these errors were encountered: