I am trying to use the jCarousel plugin for jQuery to provide scrollable (horizontal) content to my site users.
The content that I mention is mostly user-defined elements <li>, styled to give them the feel and look of a tab. so basically I'm trying to achieve the same tab effect on flakes.com. As you can imagine, users create tabs and provide tab names themselves.
jCarousel requires you to specify a fixed width for the content, for example, all of their examples are based on images with a fixed height and width. but in my case, I do not control how the user calls his tab ... which makes it impossible to guess the width of the full div container.
I tried using a stupid method, for example, guessing the width programmatically, assuming each letter is about 5 pixels and multiplies 5 by the length of the word that they gave as the name for the tab. even so, I needed to manage the css file dynamically, and I'm not sure how to do it, and even if it is possible.
Any decisions were appreciated ...
<lu>
<li class='MyTab' id='578'>This is my tab</li>
<li class='MyTab' id='579'>of which I can</li>
<li class='MyTab' id='580'>never guess</li>
<li class='MyTab' id='581'><img src='img/bullet_key.png' /> The length of</li>
</lu>
The above html is created programmatically via ajax_tabs_output.aspx, loaded into the javascript array, and jCarousel takes care of the rest.
function outputTabsArray() {
$.ajax({
url: 'ajax_tabs_output.aspx',
type: 'get',
data: 'q=array',
async: false,
success: function(out)
{
tabs_array = out;
}
});
}
function mycarousel_itemLoadCallback(carousel, state)
{
for (var i = carousel.first; i <= carousel.last; i++) {
if (carousel.has(i)) {
continue;
}
if (i > tabs_array.length) {
break;
}
carousel.add(i, mycarousel_getItemHTML(tabs_array[i-1]));
}
};
function mycarousel_getItemHTML(item)
{
return '<div class="MyTab" id="' + item.tab_id + "'>" + item.tab_name + '</div>';
};
$('#mycarousel').jcarousel({
size: tabs_array.length,
itemLoadCallback: {onBeforeAnimation: mycarousel_itemLoadCallback}
});