jsor / jcarousel

Riding carousels with jQuery.
https://sorgalla.com/jcarousel/
MIT License
1.99k stars 734 forks source link

reload method not working #777

Closed pabloavenburg closed 8 years ago

pabloavenburg commented 8 years ago

Hi. I am using jcarousel responsive plugin, which has this code:

    jcarousel.on('jcarousel:reload, jcarousel:create', function () {
      console.log('reloading carousel');
      var carousel = $(this),
            width = carousel.innerWidth();
            cantSlides = 1;
            if (width >= 1600){
                width = width / 4;
                cantSlides = 4;
            }else if (width >= 1200) {
                width = width / 3;
                cantSlides = 3;
            }else if (width >= 800) {
                width = width / 2;
                cantSlides = 2;
            }
            carousel.jcarousel('items').css('width', Math.ceil(width) + 'px');

            $('.jcarousel-control-prev')
            .jcarouselControl({
                target: '-='+cantSlides
            });

            $('.jcarousel-control-next')
            .jcarouselControl({
                target: '+='+cantSlides
      });

    })

This works great when the window is loaded (F5), but I can't get the reload event to fire. Here:

$(window).resize(function(){
  $('.jcarousel').jcarousel('reload');//This does not fire the above function. Why?
});
jsor commented 8 years ago

Multiple events must be separated by a space, not by a comma.

Correct

jcarousel.on('jcarousel:reload jcarousel:create', function () {

Wrong

jcarousel.on('jcarousel:reload, jcarousel:create', function () {
pabloavenburg commented 8 years ago

Thank you! It works like a charm now.