You're example makes sense, except since you're stepping outside the bounds of the plugin, jCarousel doesn't know to update itself. From the docs, it seems like the remove() method you mentioned would work. However, it my trials I never could get the jCarousel object to actually "do the right thing" and update it's buttons, scroll around, etc.
Because of all that, I wrote an additional method on the jCarousel class that does exactly that. You call removeAndAnimate(1) to remove the first item in the carousel and rebuild everything so that next/prev buttons are enabled/disabled, the works.
Also worth noting, the remove() function jCarousel provides prevents you from removing an item that is currently being shown, which is exactly what we wanted to do (allow the user to remove an image from the carousel by clicking on it, for example).
The implementation for removeAndAnimate(i):
removeAndAnimate: function(i) {
var e = this.get(i);
var d = this.dimension(e);
if (i < this.first) this.list.css(this.lt, $jc.intval(this.list.css(this.lt)) + d + 'px');
e.remove();
this.options.size--;
var di = this.options.visible != null ? Math.ceil(this.clipping() / this.options.visible) : null;
var li = this.list.children('li');
var self = this;
if (li.size() > 0) {
var wh = 0, i = this.options.offset;
li.each(function() {
self.format(this, i++);
wh += self.dimension(this, di);
});
this.list.css(this.wh, wh + 'px');
}
this.scroll(0,true);
this.buttons();
}
I recommend placing this directly after the remove() implementation. To access the jCarousel instance itself with jQuery, outside of the callback functions:
var carousel = $("#mycarousel").data("jcarousel");
carousel.removeAndAnimate(1);
That should work!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…