To also add to Kelly's answer. If you have flickity in a modal and changing the opacity isn't an option (i.e. in my case I use the same model for both garllery display and mobile navigation, toggling the display of each feature). You can also destroy the flickity variable and re-initialise. For example in my event handler I have:
if (/* condition for closing */) {
event.preventDefault();
lightbox.classList.remove('visible');
flckty.destroy()
lightboxCar.style.display = "none";
}
else if (/* condition for opening carousel */) {
lightboxCar.style.display = "initial";
var pageImgs = document.querySelector("main").getElementsByTagName("img");
flckty = new Flickity( '#lightbox-carousel', {
// options
"cellAlign": 'center',
});
where lightboxCar
is the carousel item on the page.