简体   繁体   中英

FlickityCall - prev/next event programmatically

To properly handle my carousel I use flickity .

It works fine, but I'm currently trying to navigate with custom buttons.

Docs say to call carousel.flickity("next") - which I tried, but I doesn't seem to work.

import * as Flickity from 'flickity';

this.$elem = value.nativeElement;
this.carousel = new Flickity(this.$elem, {
  accessibility: true,
  prevNextButtons: false,
  pageDots: false,
  setGallerySize: false,
  draggable: true,
  freeScroll: true
});

Is there an equivalent to call the next event programmatically using javascript/typescript?

Hey I got a solution for that. Use query selector to access Flickity given next buttons and click them programmatically on your custom button onClick functions. You can hide the buttons given by Flickity using css. This is a work around but not based on official docs.

/* 
    In my case I inspected the button given by Flickity and accessed those in my JS or TS file 
*/

 let temp:any = document.querySelector('.flickity-button.flickity-prev-next-button.next');
 temp.click();

In your CSS file you can add visibility property hidden so that button functionality will be intact to click programmatically but in UI as expected Flikity buttons wont be found.

.flickity-button {
    position: absolute;
    visibility: hidden;
    border: none;
    color: #8c6238 !important;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM