metafizzy / flickity

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

Flickity inside a Bootstrap dialog, is not sliding #1060

Closed vd3d closed 4 years ago

vd3d commented 4 years ago

Hi,

When I put Flickity inside a bootstrap 4 modal, it does not slide.

I have a repro case here: https://codepen.io/cdemez/pen/LYpJjEp

BTW, I have try to init flickity just after the button click, but it does not help :-(

Do you have any idea ?

desandro commented 4 years ago

You likely need to trigger resize on shown. See https://github.com/metafizzy/flickity/issues/862#issuecomment-438707067

$('.modal').on('shown.bs.modal', function (e) {
  $(".carousel").flickity('resize');
});
vd3d commented 4 years ago

Indeed, it works in the sample ... but not in my application :-(

Anyway, I do the following in Javascript (cannot make the HTML version work), when I click a button, I show the dialog, then update flickity

$('#myModal').modal('show');
var f = new Flickity(document.getElementById('myflickity'), { autoPlay: true });
f.resize();

Any idea ?

desandro commented 4 years ago
let $myModal = $('#myModal').modal('show');
let $myflickity = $('#myflickity').flickity({ autoPlay: true });
$myModal.on( 'shown.bs.modal', function() {
  $myflickity.flickity('resize');
});
vd3d commented 4 years ago

It works... thanks