I have a question regarding the jCarousel plug-in (from sorgalla). How do I remove items from it the right way?
You can see how far I've gone here. Try deleting a few items and then scrolling to the right, you'll see an "emtpy scroll" eventually, and that's what I'm trying to get rid of.
I've tried using the remove(); jQuery function instead of changing the css to display: none; but that produces a weird white blank space where the item used to be. If you look at the jquery.jcarousel.js on line 400 you'll see a remove function, but I'm not sure on how to use it.
Any help is much appreciated. Thanks!
USAGE
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):
I recommend placing this directly after the remove() implementation. To access the jCarousel instance itself with jQuery, outside of the callback functions:
That should work!
My other solution was to add a class to my loaded content and delete all the items that don't have this class in the DOM. Once "removed" by
carousel.reset()
, these elements lose systematically the added class.You will be able then to remove the white boxes with:
Add it just after the
carousel.add()
function.It works well and you don't even have to add any function to your carousel.
This is an "easy to go" solution and a click on the prev/next buttons may show a white box. To remove it, apply the same solution on the callback
buttonNextCallback
/buttonPrevCallback
.I found where the problem with white boxes comes from. JCarousel method format() doesn't replace class names, but just add new one. I've rewrote this function and it works well for me:
I combined both of your answers because none worked for me..
I added it at my init custom function
It works well..
You can add more improvements like scrolling back to the item's that have just been removed position.