davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
5.8k stars 175 forks source link

Breakpoints option #322

Closed davidjerleke closed 2 years ago

davidjerleke commented 2 years ago

Feature request is related to

Is your feature request related to an issue?

Describe the solution you'd like

// VanillaJS
const embla = EmblaCarusel(emblaNode, {
  loop: false,
  breakpoints: {
    '(min-width: 768px)': { loop: true }
  }
});

// ReactJS
const [emblaRef, emblaApi] = useEmblaCarousel({
  loop: false,
  breakpoints: {
    '(min-width: 768px)': { loop: true }
  }
});
const embla = EmblaCarusel(emblaNode, {
  loop: false,
  breakpoints: {
    '(min-width: 768px)': { loop: true }, 
    '(min-width: 420px)': { loop: false } // This will override the (min-width: 768px) breakpoint loop option
  }
});
const embla = EmblaCarusel(emblaNode, {
  loop: false,  // --> 419px screens and down will produce the following outcome { loop: false }
  breakpoints: {
    '(min-width: 420px)': { align: 'start' },  // --> 420px screens and up will produce the following outcome { align: 'start', loop: false }
    '(min-width: 768px)': { loop: true },  // --> 768px screens and up will produce the following outcome { align: 'start', loop: true }
  }
});
const embla = EmblaCarusel(emblaNode, {
  active: true, // --> 767px screens and down will activate the carousel
  breakpoints: {
    '(min-width: 768px)': { active: false }, // --> 768px screens and up won't activate the carousel
  }
});
davidjerleke commented 2 years ago

Released with v7.