0

I'm using the jCarousel script (http://sorgalla.com/jcarousel/) and I'm wondering if anyone knows of a way to dynamically set specific configuration settings based on how many items are in the carousel? For example, I'd like this to happen if there are four or less items in the carousel:

$().ready(function() {
  $('#sixMR').jcarousel({
    animation: 'slow',
    scroll: 1
  });
});

But I'd need this if there are five or more items:

$().ready(function() {
  $('#sixMR').jcarousel({
    animation: 'slow',
    scroll: 1,
    wrap: 'circular'
  });
});
1

1 Answer 1

0

Well you might be able to do it with an init callaback:

$(whatever).jcarousel({
  "initCallback": function(c, state){
      if(c.list.length < 5){
        c.options = $.extend(c.options, {
          animation: 'slow',
          scroll: 1,
          wrap: 'circular'
        });
      } else {
         c.options = $.extend(c.options, {
            animation: 'slow',
            scroll: 1
         });
      }
  }
});

Now i dpnt know for sure that will work because of how and when the option values are used... modifying them after init may actually be too late. In that case there is no way to directly plugin (unless you want to re init again, but that seems wasteful). If thats the case then the easiest thing to do is going to be to make a wrapper and decied your options and then create the carousel from there.

2
  • That did not work, but thank you very much for the effort and for pointing me in the right direction! I actually just came up with a method that does work, take a look and let me know if there's anything glaringly wrong with it. I'm still learning jQuery, and I want to make sure I'm doing things according to best practices as much as possible. Thanks again! if ($('#sixMR li').length < 5) { $('#sixMR').jcarousel({ animation: 'slow', scroll: 1 }); } else { $('#sixMR').jcarousel({ animation: 'slow', scroll: 1, wrap: 'circular' }); } Commented Dec 9, 2011 at 19:21
  • $().ready(function() { if ($('#sixMR li').length < 5) { $('#sixMR').jcarousel({ animation: 'slow', scroll: 1 }); } else { $('#sixMR').jcarousel({ animation: 'slow', scroll: 1, wrap: 'circular' }); } }); Commented Dec 9, 2011 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.