Monday, July 19, 2010

jQuery plugin jCarousel gives "No width/height set for items ..." error on Safari

Need to make sure that the container that jCarousel is applied to is visible (e.g., not styled to display:none) when the carousel is initialized (got the clue from this discussion on drupal.org). In the case of a couple carousels activated by a tabs (implemented also with jQuery), initialize the hidden carousel only when the tab is activated, say, in a callback function like this:

function myTabCallbackOnActive() {
// Find carousel object from active tab
var activetab = $('#blahblah .selected a').attr('href');
var carousel = $(activetab + '.jcarouselstrip').data('jcarousel');
if (carousel == null) {
initCarousel(activetab);
carousel = $(activetab + '.jcarouselstrip').data('jcarousel');
}
// Do other actions as needed for now-active carousel.
// For example, go to the first item:
carousel.scroll(1,false);
}

No comments:

Post a Comment